php - i want to display array in view in yii2 -
i want display array in view form don't know how ? can 1 me : controller code :
$query = new query; $query ->select(['day_name']) ->from('days') ->join( 'inner join','doctorsworkday','doctorsworkday.day_id =days.dayid'); $command = $query->createcommand(); $dataprovider = $command->queryall(); $dataprovider= array($dataprovider); return $this->render('view', [ 'model' => $this->findmodel($id), 'days'=>$days, 'doctorsworkday'=>$doctorsworkday, 'dataprovider' => $dataprovider, ])
my view code :
<?= detailview::widget([ 'model' => $dataprovider, 'attributes' => [ 'day_name' ], ]) ?>
but shows : (not set)
when use vat_dump($dataprovider) there array .. don't know how show
well firstly using detailview displaying multiple results. detailview used display detail of single data model said in docs. use gridview display multiple results. gridview accepts dataprovider not array you'll need turn array dataprovider.
fortunately can use class arraydataprovider that:
$gridviewdataprovider = new \yii\data\arraydataprovider([ 'allmodels' => $dataprovider, 'sort' => [ 'attributes' => ['day_name'], ], 'pagination' => ['pagesize' => 10] ]);
something should work.
then pass $gridviewdataprovider gridview this:
<?= gridview::widget([ 'dataprovider' => $gridviewdataprovider, 'columns' => [ 'name' ] ]) ?>
also note in controller wrapped $dataprovider in array line:
$dataprovider= array($dataprovider);
you should remove line , should work far can tell.
Comments
Post a Comment