Exemplo n.º 1
0
 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $session->set('web_id', $request->post('web_id'));
         $id = MenuRecord::getMainMenuId();
         $session->set('menu_id', $id);
     } else {
         if ($request->post('menu_id')) {
             $id = $request->post('menu_id');
             $session->set('menu_id', $id);
         } elseif ($session->get('menu_id')) {
             $menu = MenuRecord::findOne($session->get('menu_id'));
             if ($menu) {
                 $id = $session->get('menu_id');
             } else {
                 $id = MenuRecord::getMainMenuId();
                 $session->set('menu_id', $id);
             }
         } else {
             $id = MenuRecord::getMainMenuId();
             $session->set('menu_id', $id);
         }
     }
     $session->close();
     /* @var $controller \backend\controllers\MenuItemController */
     $controller = $this->owner;
     $controller->setMenu($id);
     return parent::beforeAction($action);
 }
Exemplo n.º 2
0
 /**
  * Finds the Menu model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MenuRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MenuRecord::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('back', 'The requested page does not exist.'));
 }
Exemplo n.º 3
0
 /**
  * @return MenuRecord object
  */
 public function getMenu()
 {
     return MenuRecord::findOne($this->menu_id);
 }
Exemplo n.º 4
0
 /**
  * Sets $_menu property
  * @param $id
  *
  * @throws NotFoundHttpException
  */
 public function setMenu($id)
 {
     if (($this->_menu = MenuRecord::findOne($id)) === null) {
         throw new NotFoundHttpException(Yii::t('back', 'The requested menu does not exist.'));
     }
 }