In Tbgridview How To Show Multiple Model Fields

Hi

I have two tables

  1. student (studentId, name, student_rId)

  2. registration (rId, regNumber)

Student_rId and rId is an entity relation of one is to one nature

I have used Crud to generate code

I am facing trouble to show in student view

student.studentId, student.name, registration.regNumber

My code looks as below

<?php $this->widget(‘bootstrap.widgets.TbGridView’,array(

'id'=&gt;'student-grid',


'dataProvider'=&gt;&#036;model-&gt;Search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	'studentId',


	'name',


	'student_rId',


	array(


'class'=&gt;'bootstrap.widgets.TbButtonColumn',


	),


),

)); ?>

:)

Assuming that CRUD has set up relations for you, then you should be able to access the values from the other table using the relation. Something like:




    'relationName.studentId',



I’d guess the relation name would be student in your case, so try ‘student.studentId’

No CRUD has not generated any relation code

I tried below code in relation of student model

‘studentReg’ => array(self::HAS_ONE, ‘registration’, ‘rId’)

and used

studentReg.regNumber

in TBGridView.array(…

‘columns’=>array(

‘studentId’,

‘studentReg.regNumber’,

but not getting table content displayed

correct me where I am going wrong

Thanks for helping …

Try




array(

	'name'=>'Registration',

	'value'=>'$data->studentReg->regNumber',

),