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

enter var_dump

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -