Adding two models to one view is pretty easy if they have a relation.
I’ll assume you know how to generate CRUD with gii und use the example in Relational Objects
I’ll generate CRUD for both Models which will generate Controllers and Views for models,
after this you should be ok generating controllers seperately and creating your own views
Lets say I want to include the information from JProfile in JUser view,
since each user has his/her own profile.
1 2 3 4 5 6 7 8 |
public function actionView($id) { $this->render('view',array( 'model'=>$this->loadModel($id), )); } |
1 2 3 4 5 6 7 8 9 10 |
public function actionView($id) { $model = $this->loadModel($id); $this->render('view',array( 'model_u'=>$model, 'model_p'=>$model->jProfiles, // check relations in JUser )); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php /* @var $this JUserController */ /* @var $model_u JUser */ /* @var $model_p JProfile */ $this->breadcrumbs=array( 'Jusers'=>array('index'), $model_u->userid, ); $this->menu=array( array('label'=>'List JUser', 'url'=>array('index')), array('label'=>'Create JUser', 'url'=>array('create')), array('label'=>'Update JUser', 'url'=>array('update', 'id'=>$model_u->userid)), array('label'=>'Delete JUser', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model_u->userid),'confirm'=>'Are you sure you want to delete this item?')), array('label'=>'Manage JUser', 'url'=>array('admin')), ); ?> <h1>View JUser #<?php echo $model_u->userid; ?></h1> <?php $this->widget('zii.widgets.CDetailView', array( 'data'=>$model_u, 'attributes'=>array( 'userid', 'username', 'email', ), )); ?> <?php $this->widget('zii.widgets.CDetailView', array( 'data'=>$model_p, 'attributes'=>array( 'profileid', 'name', 'surname', ), )); ?> |