本文整理匯總了PHP中common\models\Article::getRecommendArticle方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::getRecommendArticle方法的具體用法?PHP Article::getRecommendArticle怎麽用?PHP Article::getRecommendArticle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common\models\Article
的用法示例。
在下文中一共展示了Article::getRecommendArticle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionIndex
/**
* 獲取文章列表(可以按分類、標簽獲取文章列表)
* @return string
*/
public function actionIndex()
{
$category_id = Html::encode(Yii::$app->request->get('category_id'));
$tag_id = Html::encode(Yii::$app->request->get('tag_id'));
$data = Article::find()->where(['status' => Article::STATUS_DISPLAY, 'category_id' => $category_id]);
if ($tag_id) {
$article_tags = ArticleTag::find()->where(['tag_id' => $tag_id])->all();
$article_ids = ArrayHelper::getColumn($article_tags, 'article_id');
$data = $data->andWhere(['in', 'id', $article_ids]);
}
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => 20]);
//全部文章
$articles = $data->orderBy(['publish_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all();
//推薦文章
$recommendArticles = Article::getRecommendArticle();
//分類
$categories = Category::find()->where(['status' => Category::STATUS_DISPLAY])->all();
//熱門標簽
$tags = Tag::find()->orderBy(['article_count' => SORT_DESC, 'id' => SORT_DESC])->limit(10)->all();
return $this->render('index', ['articles' => $articles, 'recommendArticles' => $recommendArticles, 'categories' => $categories, 'tags' => $tags, 'category_id' => $category_id, 'tag_id' => $tag_id]);
}