2014-11-05 104 views
2

Yii是最好的,但我在從yii1到yii2複製一些代碼時遇到了一些麻煩,下面我使用yii中的代碼在一個視圖中呈現兩個模型,喜歡用yii2來複制它。感謝任何幫助。感謝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)); 
?> 

回答

3

renderPartial()yii2觀點相對應的是:

yii\base\Controller::render() 
+0

感謝阿里,幫助理清:

yii\base\View::render() 

在控制器你呈現。歡呼聲 – davidndunoon 2014-11-26 09:31:29

+0

@davidndunoon不客氣親愛的 – 2014-11-26 09:32:09

+0

在Yii2中,有一個renderPartial方法只接受2個參數,而不是Yii 1.1中的4個 – 2015-01-20 05:52:34