本文整理匯總了PHP中app\models\Menu::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP Menu::findOne方法的具體用法?PHP Menu::findOne怎麽用?PHP Menu::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Menu
的用法示例。
在下文中一共展示了Menu::findOne方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: findModel
protected function findModel($id)
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例2: validateUrl
public function validateUrl($attribute, $params)
{
$row = Menu::findOne(['url' => $this->url]);
if ($row) {
//if ($row->id != $this->post_id){
$this->addError($attribute, 'Пункт меню с таким URI уже существует.');
//}
}
}
示例3: actionCreate
/**
* 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)]);
}
}
示例4: loadModel
/**
* 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;
}