cakephp:用'contain'找到语句 [英] cakephp: find statement with 'contain'
问题描述
pre $ public $ getProfile($ id){
return $ this-> find('数组(
'conditions'=>数组('User.id'=> $ id),
'contains'=> array(
'Access'=> ; array('AccessLevel'),
'Moderator'=> array('ForumCategory')
)
));
执行cake会从查找函数正在执行的模型中加载所有的数据,加上模型中与模型相关的所有数据。大多数情况下,你不需要额外的数据,Cake完全可以满足这个需求。在上面的例子中,find语句将从 以下是cakephp书籍的链接 http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html the following User model function is from MilesJones forum plugin. Can someone tell me on what is the use of 'contain' in the find stmt. I couldn't find any example with contain in the cakephp cookbook. Any helps is appreciated.
By default when a find statement executes cake pulls all the data from the model on which the find function is executing plus all the data from the models that are associated with the model. Most of the time you don't need that extra data, Cake has containable behaviour for exactly that purpose. You can specify which associated model's data you want in your result. In the above example find statement will fetch the first record from the Here is the link from cakephp book http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html 这篇关于cakephp:用'contain'找到语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!用户模型中获取第一条记录 / code>加上来自
访问和主持人模式
的关联数据。
public function getProfile($id) {
return $this->find('first', array(
'conditions' => array('User.id' => $id),
'contain' => array(
'Access' => array('AccessLevel'),
'Moderator' => array('ForumCategory')
)
));
}
User model
plus associated data from Access and Moderator models
.