php - Yii2 : How to pass additional parameters to listview -


i read post , answer give songwut k. in question:

yii2 listview , dataprovider

but want know possible use second model in _item. suppose _item post in forum retrieves data $model i'd use different model $comment me comment on post , view post commentary 1 _item. imagie item post on facebook , display text, date , user write post. how can add comment other model? want pass $comment _item view.

i tried add new commnet in controller:

public function actionindex()     {         $model = new newsform();         $searchmodel = new newssearch();         $comment= new urcomment();         $dataprovider = $searchmodel->search(yii::$app->request->queryparams);         $dataprovider->setsort(['defaultorder' => ['id'=>sort_desc]]);          if ($model->load(yii::$app->request->post()) && $model->validate()) {             $model->savenews();             return $this->redirect(['/content/news']);         } else {             return $this->render('index', [                         'model' => $model,                         'searchmodel' => $searchmodel,                         'dataprovider' => $dataprovider,                         'comment' => $comment             ]);         }     } 

and render index. can use $comment in index how can pass _item? tried this:

 <?php                 echo listview::widget( [                     'dataprovider' => $dataprovider,                     'itemview' => '_item',                     'summary'=>'',                      'comment' => $comment                 ]); ?> 

and tried in _item:

<?= $model->getstatus($model->cnnewscontenttype_id); ?> <br>         <?php $form = activeform::begin(); ?>     <?= $form->field($comment, 'text')->textinput(['maxlength' => true])->label('treść') ?>     <?php activeform::end(); ?> 

but have error:

unknown property – yii\base\unknownpropertyexception

setting unknown property: yii\widgets\listview::comment

in _item can use $model. possible pass $comment _item view? pls me

you should use viewparams :

additional parameters passed $itemview when being rendered. property used when $itemview string representing view name.

e.g. :

<?= listview::widget( [     'dataprovider' => $dataprovider,     'itemview' => '_item',     'viewparams' => ['comment' => $comment],     'summary'=>'',  ]); ?> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -