Exemple #1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $model = new MenuItem();
     if (!empty($this->id)) {
         $model = MenuItem::findOne($this->id);
     }
     $model->setAttributes(['name' => $this->name, 'menuID' => $this->menuID, 'linkType' => $this->linkType, 'order' => $this->order, 'link' => $this->link]);
     if ($model->save(false)) {
         $this->id = $model->id;
     }
     return !empty($this->id);
 }
Exemple #2
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, it will return false.
  *
  * @param integer $id
  *
  * @return MenuItem|bool|null|static
  */
 protected function findMenuItem($id)
 {
     if (($model = MenuItem::findOne($id)) !== null) {
         return $model;
     } else {
         return false;
     }
 }
Exemple #3
0
 public function actionEdit()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if (!empty($_POST['Menu']['id'])) {
         $menu = Menu::findOne($_POST['Menu']['id']);
         $menu->name = $_POST['menu-name'];
         $menu->save();
         if (!empty($_POST['order'])) {
             foreach ($_POST['order'] as $key => $value) {
                 $item = MenuItem::findOne($value);
                 $item->parent_id = $_POST['parent'][$value];
                 $item->type_name = $_POST['name'][$value];
                 $item->order = $key + 1;
                 $item->save();
             }
         }
         return ['message' => 'ok'];
     }
 }
 /**
  * Finds the MenuItem model based on its primary key value.
  * If the model is not found, it will return false.
  *
  * @param integer $id
  * @return MenuItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findMenuItem($id)
 {
     if (($model = MenuItem::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }