public function run() { $query = Article::find()->orderBy(['created_at' => SORT_DESC])->limit($this->count); if ($this->condition != null) { $query->where($this->condition); } $articles = $query->all(); return $this->render('last-articles', ['articles' => $articles]); }
public function init() { if ($this->renderCategories) { $categories = Category::findAll(['parent_id' => $this->categoryId, 'show' => true]); $this->items = array_merge($this->items, $this->handleCategories($categories)); } if ($this->renderArticles) { $articles = Article::find()->where(['category_id' => $this->categoryId, 'show' => true])->orderBy(['position' => SORT_ASC])->all(); $this->items = array_merge($this->items, $this->handleArticles($articles)); } parent::init(); }
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]); }
private function findArticleBySeoUrl($seoUrl, $categoryId, $options = []) { $articlesSeoData = SeoData::find()->where(['entity_name' => ArticleTranslation::className(), 'seo_url' => $seoUrl])->all(); if ($articlesSeoData) { foreach ($articlesSeoData as $articleSeoData) { if ($article = Article::find()->joinWith('translations translation')->where(array_merge(['translation.id' => $articleSeoData->entity_id, 'category_id' => $categoryId, 'translation.language_id' => $this->currentLanguage->id], $options))->one()) { return $article; } } } return null; }
public function actionIndex() { return $this->render('index', ['articles' => Article::find()->with(['category', 'category.translations', 'translations'])->orderBy(['position' => SORT_ASC])->all(), 'languages' => Language::findAll(['active' => true])]); }