[英]CakePHP model->find seems to be ignoring the conditions
In my Jobs controller I have this statement under the index() function: 在我的Jobs控制器中,在index()函数下有以下语句:
$this->Job->find('all', array('conditions' => array('Job.completed' => '0', 'Job.user_id' => $this->Auth->user('id'))));
$this->set('jobs', $this->paginate());
This should show all incomplete jobs for the currently logged in user under the $jobs variable (when accessed from a view). 这应该在$ jobs变量下(从视图访问时)显示当前登录用户的所有未完成的作业。 However, I'm getting all incomplete jobs for every user.
但是,我为每个用户获得了所有不完整的工作。
$this->Auth->user('id'); //returns correct user ID for logged in user
Have I missed something? 我错过了什么吗?
I've just revisited CakePHP after months of absence and I fear I may have to relearn some of the basics. 几个月缺席之后,我才重新访问了CakePHP,我担心我可能不得不重新学习一些基础知识。
Thanks for your help! 谢谢你的帮助!
:) welcome back to cake :)欢迎回到蛋糕
$this->Job->find()
will return an array.. it doesn't modify the pagination. $this->Job->find()
将返回一个数组..它不会修改分页。 if you do : 如果您这样做:
$jobs = $this->Job->find('all', array('conditions' => array('Job.completed' => '0', 'Job.user_id' => $this->Auth->user('id'))));
pr($jobs);
you will see that the conditions are correct.. 您会看到条件正确。
to add conditions to the pagination you must change the pagination property , something like: 要为分页添加条件,您必须更改分页属性 ,例如:
$this->paginate = array(
'conditions' => array('Job.completed' => '0', 'Job.user_id' => $this->Auth->user('id')),
'limit' => 10
);
$this->set('jobs', $this->paginate());
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.