I am wanting to display posts by category, where by the URL would be something along the lines of
localhost:8888/advanced/article/category?id=2
Similar to how a single post/article is displayed in the improved advanced template (localhost:8888/advanced/article/view?id=33)
I have the following code which I need to pass the category_id at the minute if I go to localhost:8888/advanced/article/category?id=1 i get redirected to login.
public function actionCategory($id)
{
$model = new Article();
$searchModel = new ArticleSearch();
$query = Article::find()
->where(['category' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $this->render('category', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model'=>$model,
]);
}
Database
-id
-user_id
-avatar
-filename
-title
-summary
-content
-status
-category_id