简体   繁体   English

CakePHP模型->查找似乎忽略了条件

[英]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.

相关问题 CakePHP:模型->模型-> find() - CakePHP: Model->Model->find() CakePHP模型->在字段中查找和IF条件 - CakePHP model->find and IF condition in field 使用finderQuery的CakePHP 2.3模型关联可用于Model-> read(),但不适用于Model-> find() - CakePHP 2.3 model association using finderQuery works with Model->read() but not with Model->find() CakePHP 2:在$ this-> Model-> find语句中使用存储的数组作为键 - CakePHP 2: Using stored array as keys in a $this->Model->find statement 指定订单时CakePHP Model-> find('first')返回false - CakePHP Model->find('first') returns false when order specified CakePHP:在$ this-> Model-> find中使用LOCATE子句 - CakePHP: Using LOCATE clause in $this->Model->find Cakephp:Model-> find('all')是否可以返回没有模型名称的结果 - Cakephp: can Model->find('all') return results without model name CakePHP没有设置$ this-> Model-> id变量 - CakePHP not setting the $this->Model->id variable 我如何在不使用`$ this-> Model-> query()`的情况下在CakePHP中编写复杂的查找查询? - How can I write a complex find query in CakePHP without using `$this->Model->query()`? CakePHP - 名为'login'的字段自动转换为$ Model-> find()中的星号 - CakePHP - field named 'login' automatically gets converted to asterisks in $Model->find()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM