cakephp:用'contain'找到语句 [英] cakephp: find statement with 'contain'

查看:187
本文介绍了cakephp:用'contain'找到语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下用户模型函数来自MilesJones论坛插件。有人可以告诉我什么是在查找stmt中使用包含。在cakephp食谱中我找不到包含任何示例。任何帮助表示赞赏。

pre $ public $ getProfile($ id){
return $ this-> find('数组(
'conditions'=>数组('User.id'=> $ id),
'contains'=> array(
'Access'=> ; array('AccessLevel'),
'Moderator'=> array('ForumCategory')

));


解决方案

执行cake会从查找函数正在执行的模型中加载所有的数据,加上模型中与模型相关的所有数据。大多数情况下,你不需要额外的数据,Cake完全可以满足这个需求。在上面的例子中,find语句将从用户模型中获取第一条记录 / code>加上来自访问和主持人模式的关联数据。

以下是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.

public function getProfile($id) {
    return $this->find('first', array(
        'conditions' => array('User.id' => $id),    
        'contain' => array(
            'Access' => array('AccessLevel'),
            'Moderator' => array('ForumCategory')
        )
    ));
}

解决方案

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 User model plus associated data from Access and Moderator models.

Here is the link from cakephp book http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html

这篇关于cakephp:用'contain'找到语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆