duanan1228 2014-05-26 07:57
浏览 46
已采纳

CakePHP:不能将标量值用作数组

I am trying this code:

My Code snippet

public function beforeFind($query) {
        $query = parent::beforeFind($query);
        if(!isset($query['conditions'])){
            $query['conditions'] = array();
        }
        if(!$this->Authake->isAdmin()){
            if(empty($query['conditions']) || is_array($query['conditions'])){
                $query['conditions'] = array('organ_id' => $this->Organ->Group->getUserBranches());
            }
        }
        return $query;
    }

But I am getting this error

Error

Warning (2): Cannot use a scalar value as an array [APP\Model\Ticket.php, line 56]

Warning (2): Cannot use a scalar value as an array [APP\Model\Ticket.php, line 56]
  • 写回答

1条回答 默认 最新

  • donglu5047 2014-05-26 08:25
    关注

    As said by commentor that $query is not an array, and beforeFind is returning boolean. So the following line is having problem.

    $query = parent::beforeFind($query);
    

    The correction is

    There is no use of calling parent method as it is overridden it to implement own logic.

    so the correct code is

    public function beforeFind($query) {
                if(!isset($query['conditions'])){
                $query['conditions'] = array();
            }
            if(!$this->Authake->isAdmin()){
                if(empty($query['conditions']) || is_array($query['conditions'])){
                    $query['conditions'] = array('organ_id' => $this->Organ->Group->getUserBranches());
                }
            }
            return $query;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 自己写的测试驱动程序无法启动
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码