Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于联接表的cakephp条件_Php_Mysql_Cakephp_Cakephp 2.0 - Fatal编程技术网

基于联接表的cakephp条件

基于联接表的cakephp条件,php,mysql,cakephp,cakephp-2.0,Php,Mysql,Cakephp,Cakephp 2.0,这是一个查询示例,我只想在产品包含至少一个条目时获得结果 现在,如果产品不包含产品,我会得到如下结果: $results = $this->Cart->find('all', array( 'contain' => array( 'Product' => array( 'Category' => array( 'cond

这是一个查询示例,我只想在产品包含至少一个条目时获得结果

现在,如果产品不包含产品,我会得到如下结果:

 $results = $this->Cart->find('all', 
        array(
          'contain' => array(
              'Product' => array(
                  'Category' => array(
                      'conditions' => array('Category.name LIKE' => "%$query%"),
                      'fields' => array('Category.name')
                   )
              )
           ),
          'conditions'=>array(
              'Product.title LIKE' => "%$query%"
          ),                                                  
         'fields'=> array('Product.title')
        );
我根本不想得到没有类别的产品,我怎么能把它添加到条件中呢

试试这段代码

array(){
'field' => 'value'
'Product' => 'Category' => array()
}
你忘记关闭一个括号…可能是它对你有用

 $results = $this->Cart->find('all', 
                            array(
                                'contain' => array(
                                    'Product' => array(
                                        'Category' => array(
                                            'conditions' => array('Category.name LIKE' => "%$query%"),
                                            'fields' => array('Category.name')
                                        )
                                    )
                                ),
                                'conditions'=>array(
                                        'Product.title LIKE' => "%$query%"
                                ),                                                  
                                'fields'=> array('Product.title')
                            )
                        );