database - Not able to access multiple tables from CGridView -


i facing problem when trying present data multiple database tables in single cgridview in yii.

i have searched , referred enough number of articles on this. not able solve problem.

i have 2 tables name user_master , customer_master. each customer there master record in user_master too. tables follows -

user_master - user_id, name, email_id, status customer_master - customer_id, user_id, account_type, creation_date, status

in usermaster.php, code is...

<?php public function relations() { return array('customer_master'=>array(self::has_one, 'customermaster', 'user_id'),); } public function searchusers() { public $user_type; $criteria=new cdbcriteria; $criteria->alias = 't'; $criteria->compare('t.user_id',$this->user_id); $criteria->compare('t.name',$this->name,true); $criteria->compare('t.email_id',$this->email_id,true); $criteria->compare('t.status',$this->status);  $criteria->together = true;  $criteria->with = array('customer_master'); $criteria->compare('customer_master.user_id',$this->user_id,true); $criteria->compare('customer_master.user_type',$this->user_type,true);  return new cactivedataprovider($this, array('criteria'=>$criteria,              'sort'=>array('defaultorder'=>'user_id asc',),)); } ?> 

and in customermaster.php...

<?php public function relations() { return array('user_id' => array(self::belongs_to, 'usermaster', 'user_id'),); } ?> 

usermastercontroller.php has code follows..

<?php public function actionadmin() {     $model=new usermaster('search');     $model->unsetattributes();  // clear default values     if(isset($_get['usermaster']))         $model->attributes=$_get['usermaster'];          $this->render('admin',array(             'model'=>$model, )); } ?> 

in usermaster/admin.php

<?php  $this->widget('zii.widgets.grid.cgridview', array(     'id'=>'user-master-grid',     'dataprovider'=>$model->searchusers(),     'filter'=>$model,     'columns'=>array(         'user_id',         'name',         'status',                 'email_id',         array(             'name' => 'customer_master.user_type',                         //'header' => 'customer_master.user_type',             **'value' => $data->customer_master->user_type,**                      ),          array(             'class'=>'cbuttoncolumn',         ),     ), )); ?> 

by calling usermaster/admin page getting undefined variable: data.

please me out in solving problem.

thanks in advance.

try:

'value' => '$data->customer_master->user_type',  // string! 

value string, evaluated php expression...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -