如何在3 $条件[]之间应用&&?在cakephp

exc*_*145 1 cakephp

在Cakephp中,如何在这些行之间添加"AND",$ conditions [] = codition1 && codition2 && condition3;

$conditions[]= array('Flight.from LIKE' => "%".$this->request->data['Flight']['from']."%");
$conditions[]= array('Flight.to LIKE' => "%".$this->request->data['Flight']['to']."%");
$conditions[]= array('Flight.date LIKE' => "%".$this->request->data['Flight']['date']."%");
Run Code Online (Sandbox Code Playgroud)

Kai*_*Kai 5

您可以使用以下方法简化查询:

$conditions = array(
      'Flight.from LIKE' => "%".$this->request->data['Flight']['from']."%",
      'Flight.to LIKE' => "%".$this->request->data['Flight']['to']."%",
      'Flight.date LIKE' => "%".$this->request->data['Flight']['date']."%"
 );
Run Code Online (Sandbox Code Playgroud)

当条件在不同的字段上时,实际上并不需要围绕每个字段的数组.加上CakePHP会在您的条件之间自动使用AND.