コード例 #1
0
 /**
  * @param string $slug
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionView($slug)
 {
     $contentPage = ContentPage::getDb()->cache(function () use($slug) {
         return ContentPage::find()->andWhere(['active' => 1, 'slug' => $slug])->one();
     }, ContentModule::CACHE_TIME, new TagDependency(['tags' => ContentModule::CACHE_TAG]));
     if (!$contentPage) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
     // content_template_id is set in ContentUrlRule
     $templateId = Singleton::getData('content_template_id');
     if ($templateId && $this->module->enableTemplates) {
         $template = ContentTemplate::getDb()->cache(function () use($templateId) {
             return ContentTemplate::find()->andWhere(['id' => $templateId, 'active' => 1])->one();
         }, ContentModule::CACHE_TIME, new TagDependency(['tags' => ContentModule::CACHE_TAG]));
         if ($template && is_file(Yii::getAlias('@app/templates/') . $template->layout . '/layout.php')) {
             $this->layout = '@app/templates/' . $template->layout . '/layout.php';
         }
     } else {
         $this->layout = $this->module->defaultLayout;
     }
     $breadcrumbs[] = ['label' => $contentPage->name];
     //		$this->prepareBreadcrumbs($contentPage, $breadcrumbs);
     return $this->renderIsAjax('view', compact('contentPage', 'breadcrumbs'));
 }