cakephp - 如何在cakephp中连接条件数组

标签 cakephp

根据条件获取数据库结果

if($keyword!='')
  build condition;
  /*
    array('conditions' => array("AND" => array ("esl.esl_artistname LIKE"=>"%".$artistname."%",
    "esl.esl_songname LIKE"=>"%".$songname."%")),
    'limit' => $arrFind['limit'],
    'page'=>$arrFind['page']));
  */


if(!name!='')
  /* 
    array('conditions' => array("esl.esl_artistname LIKE"=>"%".$artistname."%"),
    'limit' => $arrFind['limit'],
    'page'=>$arrFind['page'] ))
  */

$this->find('all',condition);

如何做到这一点?如何连接两个条件?

最佳答案

为什么不初始化conditions数组并直接附加到它上面?

$conditions = array();
if( keyword != '' ) {
  array_push(
    'conditions'
    , array( "AND" => array ("esl.esl_artistname LIKE"=>"%".$artistname."%", "esl.esl_songname LIKE"=>"%".$songname."%" ) )
}

if( !name != '' ) {
   array_push( 'conditions', array("esl.esl_artistname LIKE"=>"%".$artistname."%")
}

$this->find( 'all', array( 'conditions' => $conditions, 'limit' => $arrFind['limit'], 'page' => $arrFind['page'];

关于cakephp - 如何在cakephp中连接条件数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3362627/

相关文章:

cakephp - 如何在 cakephp View 文件中读取 cookie 值

php - 从 url 中删除 app/webroot

ajax - Cakephp 2.4.2 - 默认布局加载而不是 ajax 布局

cakephp - Cake PHP异常错误

javascript - 默认布局 cakePHP

mysql - CakePHP 重新连接到数据库

php - cakephp中多个模型的单一分页

cakephp - 使用 CakePHP 提供 JSONP 的正确方法是什么?

php - 绑定(bind)模型后我的条件不工作 Cakephp

templates - Cakephp 3 中的布局?