找一个查询
根据 id 查找单个记录。
$model = User::findOne($id);
根据 id 选择单列。
$model = User::findOne($id)->name;
根据条件从数据库中检索单个记录。
$model = User::find()->one(); // give first record
$model = User::find()->where(['id' => 2])->one(); // give single record based on id
根据条件从数据库中选择单列记录。
$model = User::find()->select('name,email_id')->where(['id' => 1])->one();
要么
$model = User::find()->select(['id','name','email_id'])->where(['id' => 1])->one();
排序依据
$model = User::find()->select(['id','name','email_id'])->orderBy(['id' => SORT_DESC])->one();
OR
$model = User::find()->select(['id','name','email_id'])->orderBy(['id' => SORT_ASC])->one();