简体   繁体   中英

Yii2 render two models on one view

Yii is the best but I'm having a wee bit of trouble replicating some of the code from yii1 to yii2, below I use the code in yii to render two models in one view and would like to replicate this using yii2. Grateful for any help. thanks

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));
?>

The equivalent of renderPartial() in yii2 view is:

yii\base\View::render()

In controller you render with:

yii\base\Controller::render()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM