cakephp或条件

前端之家收集整理的这篇文章主要介绍了cakephp或条件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
原创 posted在cakePHP问答,但我会把它放在这里希望得到一些答案.

我有一大堆公司的状态为0,但有时会获得更高的地位.现在我想使用高状态(如果存在),但如果没有,则恢复为0.我已经尝试了一大堆不同的方法,但是我总是只得到状态为0的状态,或者处于状态的对象,如果存在,则不会给出状态,如果不存在则为0.

给我只有我指定的状态,不给我的状态0:

@H_404_5@'Company' => array ( 'conditions' => array ( 'OR' => array( 'Company.status' => 0,'Company.status' => $status,) ) )

给我只有0的状态:

@H_404_5@'Company' => array ( 'conditions' => array ( 'OR' => array( 'Company.status' => $status,'Company.status' => 0 ) ) )

代码中的状态定义和检索数据:

@H_404_5@function getCountry($id = null,$status = null) { // Bunch of code for retrieving country with $id and all it's companies etc,all with status 0. $status_less_companies = $this->Country->find... if ($status) { $status_companies = $this->Country->find('first',array( 'conditions' => array( 'Country.id' => $id ),'contain' => array( 'Product' => array ( 'Company' => array ( 'conditions' => array ( 'OR' => array( 'Company.status' => $status,'Company.status' => 0 ) ) ) ) ) ) } // Mergin $status_less_companies and $status_companies and returning data to flex application. }

我更改了这个问题的模型的名称,只是为了更有意义,当我告诉他们我的flex应用程序与cakePHP一起工作时,人们总是吓倒了.我猜这个问题的逻辑是没有道理的,但相信我在我的应用程序中有意义.

谢谢!

我不知道你期望什么结果.如果要检索status = 0的所有记录,加上假设状态= 3,则可以使用“IN”而不是“OR”.

在蛋糕里,你可以这样写:

@H_404_5@$status = 3; $conditions = array('Company.status' => array(0,$status));

猜你在找的PHP相关文章