[英]Yii2 Listview how to display data in view
問候
我想在Yii2中顯示來自我的Atividades模型的數據
我的AtividadesController具有以下用於actionView2的代碼
public function actionView2()
{
$query = new Query;
$dataProvider = new ActiveDataProvider([
'query' => $query->from('Atividades'),
'pagination' => [
'pageSize' => 20,
],
]);
// get the posts in the current page
$posts = $dataProvider->getModels();
return $this->render('view2', ['dataProvider' => $dataProvider, 'posts' => $posts]);
}
在我的“視圖2”中,我出現以下“列表視圖”,其中顯示的消息顯示4個項目中的4個,但不顯示這些項目
<?= ListView::widget([
'dataProvider' => $dataProvider,
]); ?>
在Y1.xx中,我有一個名為“屬性”的屬性,用於顯示模型字段
我如何在此Listview中的Yii2中顯示模型文件
提前謝謝了
我已經自己解決了:)
不難
在我的View2中編寫以下代碼
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_view2',
]); ?>
然后復制一個原始視圖文件,將其名稱更改為_view2,將其放在相同的文件夾中,並根據需要設置樣式
在我的ActividadesController中,將actionView2代碼更改為:
public function actionView2()
{
$dataProvider = new ActiveDataProvider([
'query' => Atividades::find(),
'pagination' => [
'pageSize' => 20,
],
]);
// get the posts in the current page
$posts = $dataProvider->getModels();
return $this->render('view2', ['dataProvider' => $dataProvider]);
}
_View2代碼
<?= DetailView::widget([
'model' => $model,
'attributes' => [
//'id',
'atividade',
'descricao:ntext',
//'ativo',
],
]) ?>
解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.