How can I get category name within the category view.
I have the following code in my controller that renders my category using the id parameter as the category id.
For example if you go to localhost:8888/advanced/article/category?id=1 will return all posts with category id of 1.
So some how i need to pass the id parameter in the actionCategory or in my view to the model function Category Name.
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,
]);
}
In my view which renders the single post it uses the model function CategoryName which requires category id but i can not see how it’s past.
Category Name function
public function getCategoryName($category = null)
{
$category = (empty($category)) ? $this->category : $category ;
if ($category === self::CATEGORY_ECONOMY)
{
return Yii::t('app', 'Economy');
}
elseif ($category === self::CATEGORY_SOCIETY)
{
return Yii::t('app', 'Society');
}
else
{
return Yii::t('app', 'Sport');
}
}