[英]cakephp use another model within model
我有兩個名為message.php
和user.php
模型
在message.php中,我有以下方法來計算已驗證用戶的消息數。
<?php
class Message extends AppModel {
...
...
...
function getInboxCount($userId) {
// Here I want to get list of ids of verified users. It means I need to use User model for this. How is it possible?
// $ids = $this->User->find('list', array('conditions' => array('User.status' => 'verified'))); Will this work?
}
}
?>
那么如何在消息模型中使用用戶模型?
如果兩個模型以任何方式關聯(消息屬於用戶左右),則可以使用以下方法簡單地訪問它:
$this->User->find(...);
如果它們沒有關聯,則可以使用以下方法隨時導入任何其他模型:
$User = ClassRegistry::init('User');
$User->find(...);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.