找一個查詢
根據 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();