Yii是最好的,但是我在将一些代码从yii1复制到yii2时遇到了一些麻烦,下面我使用yii中的代码在一个视图中渲染两个模型,并希望使用yii2复制它。感谢任何帮助。感谢
VwContractDetailsController
public function actionView($id)//create new dataprovider and pass param from url
{
$events=$dataProvider=new CActiveDataProvider('VwContractEvents', array(
'criteria'=>array(
'condition'=>'Contractkey_id=:aid',
'params'=>array(':aid'=>$id)
),
'pagination'=>array(
'pageSize'=>2
),
'sort' => array(
'defaultOrder' => 'EventDate DESC',
),
));
$this->render('view',array(
'model'=>$this->loadModel($id),
'events'=>$events,
));
}
vwContractEvents Index //provide full path for itemview
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'/vwcontractevents/_view',
'enablePagination' => true,
)); ?>
vwContractDetails view //render VwcontractEvents/index on vwContractDetails view
<?php
$this->renderPartial('/VwContractEvents/index',array('dataProvider'=>$events));
?>
答案 0 :(得分:3)
renderPartial()
视图中的yii2
相当于:
yii\base\View::render()
在控制器中,您使用:
进行渲染yii\base\Controller::render()