Esempio n. 1
0
 public function bootstrap($app)
 {
     foreach (Yii::$app->appLanguage->getAppLanguages() as $language) {
         // slug
         $slug = CmsPageService::getSlugById(45, $language);
         // add rules
         $app->getUrlManager()->addRules(['<language:' . $language . '>/<cms_slug:' . $slug . '>' => 'contact/contact/index', '<language:' . $language . '>/<cms_slug:' . $slug . '>/<action[\\w\\-]+>' => 'contact/contact/<action>'], false);
     }
 }
Esempio n. 2
0
 public function bootstrap($app)
 {
     foreach (Yii::$app->appLanguage->getAppLanguages() as $language) {
         // slug
         $slug = CmsPageService::getSlugById(46, $language);
         // add rules
         $app->getUrlManager()->addRules([['pattern' => '<language:' . $language . '>/<cms_slug:' . $slug . '>/<page:\\d+>', 'route' => 'news/news/index', 'defaults' => ['page' => 1]]], false);
     }
 }
 /**
  * Find page
  * @throws HttpException
  */
 public function beforeAction()
 {
     // request
     $request = Yii::$app->request;
     if ($slugParam = $request->get($this->slugParam, false)) {
         // controller
         $controller = Yii::$app->controller;
         // view
         $view = $controller->view;
         // cache key
         $cacheKey = 'cms_page_slug:' . $slugParam . ':' . Yii::$app->language;
         // get from cache
         if (($dataPage = Yii::$app->commonCache->get($cacheKey)) === false) {
             $cmsPage = CmsPage::find()->innerJoinWith(['cmsPageI18ns' => function ($query) use($slugParam) {
                 $query->where(['slug' => $slugParam, 'i18n_id' => Yii::$app->language]);
             }, 'cmsLayout'])->where(['activated' => 1])->asArray()->one();
             if ($cmsPage !== null && isset($cmsPage['cmsPageI18ns'][0])) {
                 $cmsPageContents = CmsPageContent::find()->innerJoinWith(['cmsPageContentI18ns' => function ($query) {
                     $query->where(['i18n_id' => Yii::$app->language]);
                 }])->where(['cms_page_id' => $cmsPage['id']])->orderBy(['index' => SORT_ASC])->asArray()->all();
                 Yii::$app->commonCache->set($cacheKey, ['cmsPage' => $cmsPage, 'cmsPageContents' => $cmsPageContents], $cmsPage['cache_duration'], new TagDependency(['tags' => [CmsPageComponent::getCacheTag(), CmsPageComponent::getCacheTag($cmsPage['id']), CmsPageComponent::getCacheTag($cmsPage['id'], $cmsPage['cmsPageI18ns'][0]['slug'], Yii::$app->language)]]));
             }
         } else {
             $cmsPage = $dataPage['cmsPage'];
             $cmsPageContents = $dataPage['cmsPageContents'];
         }
         if (!empty($cmsPage) && !empty($cmsPageContents)) {
             $view->title = $cmsPage['cmsPageI18ns'][0]['html_title'];
             if ($cmsPage['cmsPageI18ns'][0]['html_description'] != '') {
                 $view->registerMetaTag(['name' => 'description', 'content' => $cmsPage['cmsPageI18ns'][0]['html_description']]);
             }
             if ($cmsPage['cmsPageI18ns'][0]['html_keywords'] != '') {
                 $view->registerMetaTag(['name' => 'keywords', 'content' => $cmsPage['cmsPageI18ns'][0]['html_keywords']]);
             }
             $controller->layout = $cmsPage['cmsLayout']['path'];
             $this->renderView = $cmsPage['cmsLayout']['view'];
             $this->parseCmsPageContents($cmsPageContents);
             foreach ($cmsPageContents as &$cmsPageContent) {
                 if (isset($cmsPageContent['cmsPageContentI18ns'][0])) {
                     $view->blocks['cms_block_page_' . $cmsPageContent['index']] = $cmsPageContent['cmsPageContentI18ns'][0]['content'];
                 }
             }
         } else {
             throw new HttpException(404);
         }
     } else {
         throw new HttpException(404);
     }
 }