Exemplo n.º 1
0
 protected function findBlogPost($slug)
 {
     $blogPost = BlogPost::findBySlug($slug);
     if (!isset($blogPost)) {
         throw new HttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $blogPost;
 }
Exemplo n.º 2
0
 private function generateURLForSelectedLanguage($currentLanguage)
 {
     $params = Yii::$app->request->queryParams;
     $controllerName = Yii::$app->controller->getUniqueId();
     unset($params['language']);
     $routeYii = Yii::$app->controller->getRoute();
     $route = array_merge([$routeYii], $params);
     /*TODO: Refactor this code, it's not semantic an it's messy */
     if ($routeYii == 'blog/view') {
         $blogPost = BlogPost::findBySlug($params['slug'], $currentLanguage);
         $params['slug'] = $blogPost->slug;
         if (BlogPost::findBySlug($params['slug'], Yii::$app->language) === null) {
             $routeYii = 'blog/index';
             $params = [];
         }
         $route = array_merge([$routeYii], $params);
     } elseif ($routeYii == 'blog/category-index') {
         $blogCategory = BlogCategory::findBySlug($params['slug']);
         $blogCategory->setLanguage(Yii::$app->language);
         $params['slug'] = $blogCategory->slug;
         $route = array_merge([$routeYii], $params);
     } elseif ($controllerName == 'flat-page' && Yii::$app->id == 'app-frontend') {
         $flatPage = FlatPage::findBySlugFallback($params['slug'], $currentLanguage);
         if (isset($flatPage)) {
             $params['slug'] = $flatPage->slug;
         } else {
             $params = [];
             $routeYii = 'site/index';
         }
         $route = array_merge([$routeYii], $params);
     } elseif ($routeYii == 'site/error') {
         $routeYii = 'site/index';
         $params = [];
         $route = array_merge([$routeYii], $params);
     }
     return Url::toRoute($route);
 }