/** * Generate sitemap */ public function actionGenerateSitemap() { $siteMapFile = new File(); $siteMapFile->writeUrl(['site/index'], ['priority' => '0.9']); $siteMapFile->writeUrl(['site/contact']); $pages = CmsModel::find()->where(['status' => CmsStatus::ENABLED])->all(); foreach ($pages as $page) { $siteMapFile->writeUrl([$page->url]); } $siteMapFile->close(); return self::EXIT_CODE_NORMAL; }
/** * @throws \yii\web\NotFoundHttpException * @return string */ public function run() { if ($this->pageId === null) { $this->pageId = Yii::$app->request->get('pageId'); } if (!is_null($this->pageId)) { $model = CmsModel::findOne($this->pageId); if ($model) { $model->content = $this->parseBaseTemplateParams($model->content); if (!empty($this->layout)) { $this->controller->layout = $this->layout; } return $this->controller->render($this->view, ['model' => $model]); } } throw new NotFoundHttpException('The requested page does not exist.'); }
/** * Finds the CmsModel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $id * * @return CmsModel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CmsModel::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(App::t('yii2mod', 'The requested page does not exist.')); } }
/** * Returns the validation rules for attributes. * @return array validation rules */ public function rules() { return ArrayHelper::merge([[['id', 'url', 'title', 'status'], 'safe']], parent::rules()); }
/** * Find CmsModel * * @return null|CmsModel * * @throws NotFoundHttpException */ protected function findModel() { if (($model = CmsModel::findOne($this->pageId)) !== null) { return $model; } throw new NotFoundHttpException(Yii::t('yii2mod.cms', 'The requested page does not exist.')); }