/** * @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')) { $id = $request->post('web_id'); $session->set('web_id', $id); } elseif ($session->get('web_id')) { $web = WebRecord::findOne($session->get('web_id')); if ($web) { $id = $session->get('web_id'); } else { $id = WebRecord::getMainWebId(); $session->set('web_id', $id); } } else { $id = WebRecord::getMainWebId(); $session->set('web_id', $id); } $session->close(); /** @var $controller MenuController */ $controller = $this->owner; $controller->setWeb($id); return parent::beforeAction($action); }
/** * @inheritdoc */ public function init() { parent::init(); $session = Yii::$app->session; if (WebRecord::existsMoreWebRecords()) { if (!$session->has('web')) { $session->set('web', \Yii::$app->request->get('web', \Yii::$app->params['defaultWeb'])); } if (!($this->web = WebRecord::findOne(FrontEndHelper::getWebIdFromTextId($session->get('web'))))) { $session->set('web', \Yii::$app->params['defaultWeb']); throw new NotFoundHttpException(Yii::t('front', 'The requested page does not exist.')); } } else { $this->redirect(['install/default/index']); } if (!$this->web) { $this->web = WebRecord::findOne(FrontEndHelper::getWebIdFromTextId($session->get('web'))); } $session->set('web', null); $this->setWebTheme($this->web->theme); \Yii::$app->language = \Yii::$app->request->get('language', \Yii::$app->params['defaultLanguage']); $this->language = LanguageRecord::findOne(FrontEndHelper::getLanguageIdFromAcronym()); }
/** * Finds the Web model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return WebRecord the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = WebRecord::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException(Yii::t('back', 'The requested page does not exist.')); }
/** * Sets $_web property * @param integer $id * * @throws NotFoundHttpException */ public function setWeb($id) { if (($this->_web = WebRecord::findOne($id)) === null) { throw new NotFoundHttpException(Yii::t('back', 'The requested web does not exist.')); } }