2017-07-14 82 views
0

我宣佈:錯誤的ActiveRecord查詢Yii2

$query = Country::find(); 

它的工作原理:

$countries = $query->orderBy('name') 
->offset($pagination->offset) 
->limit($pagination->limit) 
->all(); 

這不起作用:

$countries = $query->orderBy('name') 
->all(); 

PHP的警告 - 警予\基地\ ErrorException htmlspecialchars()期望 參數1爲字符串,數組爲

它的工作原理:

$countries = $query->where(['country.code' => 'AU'])->count(); 

這不起作用:

$countries = $query->where(['country.population' > 4444444])->all(); 

無效參數 - 警予\基地\ InvalidParamException 操作員 '' 需要兩個操作數。

我讀https://github.com/yiisoft/yii2/blob/master/docs/guide/db-active-record.md但我不能完全理解的想法又

回答

0

一是「不工作」的查詢看起來不錯,請更新此錯誤堆棧跟蹤問題。

二:

$countries = $query->where(['country.population' > 4444444])->all(); 

這裏>你使用,改變這=>,它會工作。如果你想檢查這個字段是否多於/少於,你必須通過它像3 params陣列:

$countries = $query->where(['>', 'country.population', 4444444])->all();