我正在尝试这段代码:
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;
}
但我收到此错误
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]
答案 0 :(得分:1)
如commentor所述,$ query不是数组,而beforeFind返回boolean。所以下面的一行有问题。
$query = parent::beforeFind($query);
更正是
没有使用调用父方法,因为它被覆盖它以实现自己的逻辑。
所以正确的代码是
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;
}