I got the output of student and employee with join by doing d following changes…
I changed my employee relation as…
public function relations()
{
return array(
'reg_no'=>array( self::BELONGS_TO, 'Student', 'reg_no' ),
);
}
Used another search cirteria as ($model->searchEmployees())…
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'employee-view-grid',
'dataProvider'=>$model->searchEmployees(),
'filter'=>$model,
'columns'=>array(
'e_no',
array('name'=>'studentName', 'value'=>'$data->student->reg_no'), // student id
array('name'=>'fatherName', 'value'=>'$data->student->s_name'), // student name
'e_name',
'desig',
'reg_no',
array('class'=>'CButtonColumn',
'template'=>'{view}'),
),
)); ?>
Added another search cirteria to my employee model that returns the data as a CActiveDataProvider.
public function searchEmployees()
{
$criteria=new CDbCriteria;
$criteria->alias = 'i';
$criteria->compare('e_no',$this->e_no);
$criteria->compare('e_name',$this->e_name,true);
$criteria->compare('desig',$this->desig,true);
$criteria->compare('reg_no',$this->reg_no);
$criteria->join= 'JOIN employee d ON (i.reg_no=d.reg_no)';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Now i’m getting the join of employee and student as output… But still i have a doubt of including the 2 fields from student table to employee using the code said by Emily Dickinson…
array('name'=>'studentName', 'value'=>'$data->student->reg_no'), // student id
array('name'=>'fatherName', 'value'=>'$data->student->s_name'), // student name
If i include this code in my gridview when it displayed an error message as "studentName not in the employee" like that…
pls hell me to solve this problem… 