Monday, 19 June 2017

Create CListView of a model class in another models view Yii

Create CListView of a model class in another models view Yii


Suppose we have two models: Project and User, in which each Project owns a number of Users. We wish to display a list of associated users in the project instances view

Modify the protected/views/project/view.php by adding the following line in the script file:


<?php $this->renderPartial(_viewUser, array(project=>$model)); ?>

Next create a partial view protected/views/project/_viewUser.php with the following codes for its implementation:


<?php
$users=new CActiveDataProvider(User,
array(
criteria=>array(
condition=>audit_project_id=:projectId,
params=>array(:projectId=>$project->id),
),
),
array(
pagination=>array(
pageSize=>20,
),
)
);

$this->widget(zii.widgets.CListView, array(
dataProvider=>$users,
viewData=>array(project=>$project),
itemView=>/user/_view,
));
?>

download
alternative link download

Like the Post? Do share with your Friends.