I am using yii2 grid view widget like below
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'name',
'visible' => empty($visbleValue) ? '1':'0',
'value' => function($model){
return $model->name;
}
],
[
'attribute' => 'account',
'visible' => empty($visbleValue) ? '0':'1',
'value' => function($model){
return implode(', ', ArrayHelper::map($model->accounts, 'id', 'account_name'));
}
],
[
'attribute' => 'Document',
'visible' => empty($visbleValue) ? '1':'0',
'value' => function($model, $index, $column) {
return Document::findOne(['user_id' => $model->id,])->document_name;
},
'label' => 'Document',
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
This all are working fine, but i want prepare columns array values(attribute values like name,account,document) using model or controller, how to do that.
Controller
public function actionVerficationDetails()
{
$session = Yii::$app->session;
$visbleValue= $session->get('visbleValue');
$searchModel = new VerficationDetailsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('VerficationDetails', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'visbleValue' => $visbleValue,
]);
}
Here i print dataprovider it will print some empty query objects, no data will come. Please help anyone.