本文整理汇总了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]);
}