2014-12-23 172 views
0

問候Yii2列表視圖如何在視圖中顯示的數據

我想在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我有一個稱爲屬性「屬性」用於顯示的模型字段

如何能我顯示此列表視圖裏面Yii2模型的Fileds

提前感謝

+0

的大膽和美麗! – Marecky

+0

你是什麼意思? –

+0

Bold font man :)) – Marecky

回答

4

我已經自己解決了吧:)

這是不難

在我的視圖2寫了下面的代碼

<?= 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', 
    ], 
]) ?> 

解決

相關問題