protected function findModel($id) { if (($model = Menu::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function validateUrl($attribute, $params) { $row = Menu::findOne(['url' => $this->url]); if ($row) { //if ($row->id != $this->post_id){ $this->addError($attribute, 'Пункт меню с таким URI уже существует.'); //} } }
/** * Creates a new Link model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $menuId * @return mixed */ public function actionCreate($menuId) { $model = new Link(); if ($model->load(Yii::$app->request->post())) { $model->menu_id = $menuId; if ($model->save()) { return $this->redirect(['menu/view', 'id' => $model->menu_id]); } } else { return $this->render('create', ['model' => $model, 'menu' => Menu::findOne($menuId)]); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Menu::findOne($id); if ($model === null) { throw new \yii\web\HttpException(404, 'The requested page does not exist.'); } return $model; }