CakePHP 忽略可包含的分页?
我想要 cakephp 分页数据并仍然使用 containable
,但由于某种原因,它似乎忽略了我对 contain
任何内容的请求,只是将整个 Tenant 还给我
行。在我的 TenantsController
中,我有以下代码:
$conditions = array('ManagersTenant.manager_id'=>$this->Auth->User('id'));
$this->Tenant->ManagersTenant->recursive = 1;
$this->set('tenants',$this->paginate($this->Tenant->ManagersTenant, $conditions, array(
'recursive'=>1,
'contain'=>array(
'username'
)
)
));
我只是尝试检索 Tenant
但仅显示 用户名
(Tenant< /code> 只是我的
User
模型的别名)。
我在这里做错了什么?如果有帮助的话,cakephp 会在Group
列下向我抛出一个未定义索引:组 通知。我相信我的模型关系是找到的,因为我可以使用 find() 使 cake 检索正确的数据,只是当我尝试使用分页时它会中断。
I want to have cakephp paginate data and still use containable
, but for some reason it seems to ignore my pleas to contain
anything and just gives me back the entire Tenant
row. In my TenantsController
I have the following code:
$conditions = array('ManagersTenant.manager_id'=>$this->Auth->User('id'));
$this->Tenant->ManagersTenant->recursive = 1;
$this->set('tenants',$this->paginate($this->Tenant->ManagersTenant, $conditions, array(
'recursive'=>1,
'contain'=>array(
'username'
)
)
));
I'm simply trying to retrieve a Tenant
but display only the username
(Tenant
is just an alias for my User
model).
What am I doing wrong here? If it helps, cakephp is throwing an Undefined Index: Group notice at me under the Group
column. I believe my model relationships are find because I can make cake retrieve the right data using find()
, it's just when I try to use pagination that it breaks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要使用模型名称作为键:
其次,使用 Containable 行为胜过递归,因此不必费心设置它。
Firstly, you need to use the model name as the key:
Secondly, using the Containable behaviour trumps recursive, so don't bother setting it.