public function loadModel($id) { $model = \app\models\Banner::findOne($id); if ($model === null) { throw new \yii\web\HttpException(404, 'Запрашиваемая страница не существует.'); } return $model; }
public function uniquedName($attribute, $params) { if (!$this->hasErrors()) { $banner = Banner::findOne(['name' => $this->name]); if ($banner) { $this->addError($attribute, '该导航名已存在'); } } }
/** * Finds the Banner model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Banner the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Banner::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }