3

My aim it to select lines in which etat_ce is one of the items in my array.

For some reason I can't find the right syntax in the cookbook for this kind of request.

$etat = array('livre', 'partiellement_livre', 'valide');
$out = $this->find('all', array('conditions' => array('etat_ce ' => $etat)));

When I do it this way, cake pops me a warning :

Notice (8): Undefined offset: 1 [CORE\Cake\Model\Datasource\DboSource.php, line 2549]

When I keep only one item in the array it works. Is is a problem with my syntax ?

EDIT: I use cake php ver 2.3.5 Many thanks !

4

2 回答 2

5

'etat_ce' => 删除空格?或者尝试使用型号名称?'型号名称.etat_ce'

于 2013-07-24T13:38:12.140 回答
0

数组键有一个额外的空间

如果有疑问 -查看来源

if (strpos($key, ' ') === false) {
    $operator = '=';
} else {
    list($key, $operator) = explode(' ', trim($key), 2);

错误是因为条件数组中的键包含一个空格 - 如问题所示:

$out = $this->find('all', array('conditions' => array('etat_ce ' => $etat)));
                                                              ^

这混淆了条件解析逻辑,要纠正它只需删除空格:

$out = $this->find('all', array('conditions' => array('etat_ce' => $etat)));
                                                              ^

并且错误消失,并且条件符合预期Foo.etat_ce = 'whatever'

于 2013-07-24T13:24:38.553 回答