Beispiel #1
0
 public function getImagePath($id, $type, $category)
 {
     $dir = Yii::getAlias('@frontend/web/images/articles/');
     $article = Article::findOne($id);
     $imagePath = $dir . $type . '/' . $article->{$type} . '-' . $category . '.jpg';
     return $imagePath;
 }
 public function actionIndex($id = null)
 {
     if (empty($id)) {
         $article = Article::find()->one();
     } else {
         $article = Article::findOne($id);
     }
     $articleTranslation = $article->translation;
     $this->view->title = $articleTranslation->seoTitle;
     $this->view->registerMetaTag(['name' => 'description', 'content' => html_entity_decode($articleTranslation->seoDescription)]);
     $this->view->registerMetaTag(['name' => 'keywords', 'content' => html_entity_decode($articleTranslation->seoKeywords)]);
     // default view name
     $articleView = 'index';
     if (!empty($article->view)) {
         $articleView = $article->view;
     } else {
         if (!empty($article->category)) {
             if (!empty($article->category->article_view)) {
                 $articleView = $article->category->article_view;
             }
         }
     }
     return $this->render($articleView, ['article' => $article]);
 }
Beispiel #3
0
 /**
  * Creates a URL according to the given route and parameters.
  * @param UrlManager $manager the URL manager
  * @param string $route the route. It should not have slashes at the beginning or the end.
  * @param array $params the parameters
  * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
  */
 public function createUrl($manager, $route, $params)
 {
     if (($route == $this->articleRoute || $route == $this->categoryRoute) && !empty($params['id'])) {
         $id = $params['id'];
         $pathInfo = '';
         $parentId = null;
         $language = Language::findOne(['lang_id' => $manager->language]);
         if ($route == $this->articleRoute) {
             $article = Article::findOne($id);
             if ($article->getTranslation($language->id) && $article->getTranslation($language->id)->seoUrl) {
                 $pathInfo = $article->getTranslation($language->id)->seoUrl;
                 $parentId = $article->category_id;
             } else {
                 return false;
             }
         } else {
             if ($route == $this->categoryRoute) {
                 $category = Category::findOne($id);
                 if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                     $pathInfo = $category->getTranslation($language->id)->seoUrl;
                     $parentId = $category->parent_id;
                 } else {
                     return false;
                 }
             }
         }
         while ($parentId != null) {
             $category = Category::findOne($parentId);
             if ($category->getTranslation($language->id) && $category->getTranslation($language->id)->seoUrl) {
                 $pathInfo = $category->getTranslation($language->id)->seoUrl . '/' . $pathInfo;
                 $parentId = $category->parent_id;
             } else {
                 return false;
             }
         }
         if (!empty($this->prefix)) {
             $pathInfo = $this->prefix . $pathInfo;
         }
         return $pathInfo;
     }
     return false;
 }
 public function actionSwitchShow($id)
 {
     /* @var Article $article */
     if ($article = Article::findOne($id)) {
         $article->show = !$article->show;
         $article->save();
     }
     return $this->redirect(Url::to(['/articles/article']));
 }