I’ve written a very simple blog and I want to display the entries in a list view grouped by category.
In my KnowledgeCategory model I have
public function getKnowledgeItems()
{
return $this->hasMany(KnowledgeItem::className(), ['category_id' => 'id']);
}
In my KnowledgeItem model I have
public function getCategory()
{
return $this->hasOne(KnowledgeCategory::className(), ['id' => 'category_id']);
}
In my index.php
<div class="knowledge-item-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Knowledge Item', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<p>
<?= Html::a('Create Category', ['knowledge-category/create'], ['class' => 'btn btn-success']) ?>
</p>
<?= \yii\widgets\ListView::widget([
'dataProvider' => $dataProvider,
'viewParams' => ['category'=>'xxx'],
'itemView' => '_item',
'layout' => '<div class="row">{items}</div><div class="text-center">{pager}</div>',
// 'filterModel' => $searchModel,
])?>
etc
in _item.php
<?php
use yii\helpers\Html;
use yii\helpers\Url;?>
<?= Html::a ($model->title, ['knowledge/view', 'id'=>$model->id])?>
<?=$model->preview?>
What am I missing?