我是yii1的新手。我想将以下查询转换为yii2。我可以知道yii2中条件和参数之间的区别吗?
$criteria = new CDbCriteria();
$criteria->select = 'amount, name, level';
$criteria->condition = "account_type = :account_type";
$criteria->params=(array(':account_type'=>'credit'));
$result = $this->model()->find($criteria);
我试过以下样本。但它没有给我与yii1查询相同的回报。
$result = Model::find()
->select(['amount, name, level'])
->where(['account_type' => $account_type, 'account_type' => 'credit'])
->one();
答案 0 :(得分:0)
试试这个:
$result = Model::find()
->select(['amount, name, level'])
->where(['account_type' => 'credit'])
->one();