コード例 #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $cssClass = @$this->options['class'];
     parent::init();
     // significant order
     if ($cssClass != $this->options['class']) {
         \yii\helpers\Html::removeCssClass($this->options, 'nav');
     }
     $this->items = Item::find()->select(['*', 'parent_id' => '(IF(pid=1,"",pid))', 'name' => 'title'])->where(['visible' => true])->andWhere(['<>', 'pid', ''])->indexBy('id')->orderBy(['rank' => SORT_ASC])->asArray()->all();
 }
コード例 #2
0
 /**
  * Renders common page view.
  * @param string $url relative url from route.
  * @return string
  * @throws \yii\web\HttpException
  */
 public function actionView($url = '/')
 {
     /**
      * @var Item $model
      */
     if (!($model = Item::getCurrentPage($url))) {
         throw new \yii\web\HttpException(404, \Yii::t('modules/page', "Page not found"));
     }
     if ($model->layout) {
         $this->layout = $model->layout;
     }
     return $this->render('view', compact('model'));
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function parseRequest($manager, $request)
 {
     if (!($result = parent::parseRequest($manager, $request))) {
         return false;
     }
     if ($this->enforceSeo) {
         Item::getCurrentPage($request->pathInfo);
         // sets seo meta tags
     }
     $manager->rules = array_filter($manager->rules, function ($rule) {
         return !$rule instanceof $this;
     });
     if (!($result2 = $manager->parseRequest($request))) {
         return $result;
     }
     return \Yii::$app->createController($result2[0]) ? $result2 : $result;
 }
コード例 #4
0
 public function down()
 {
     $this->dropTable(Item::tableName());
 }
コード例 #5
0
 /**
  * Finds the Item model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Item the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 public function findModel($id = null)
 {
     if ($id === null) {
         return new Item();
     }
     if (($model = Item::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('modules/page', 'The requested page does not exist.'));
     }
 }