Yii Framework Forum: Building CGridView - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Building CGridView Rate Topic: -----

#1 User is offline   GeneralVini 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 03-July 10

Posted 05 July 2010 - 09:40 AM

I have the following tables in my database:

tick
|idTick|idTema

tema
|idTema|nomeTema

tick.idTema is a foreign key to tema.idTema

The code
$dataProvider=new CActiveDataProvider('Tick');
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'idtick',         
        'idtema',  
        array(            
            'class'=>'CButtonColumn',
        ),
    ),
));



How can i show nomeTema in the grid ???

thxs !!!
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 05 July 2010 - 11:14 AM

View PostGeneralVini, on 05 July 2010 - 09:40 AM, said:

I have the following tables in my database:

tick
|idTick|idTema

tema
|idTema|nomeTema

tick.idTema is a foreign key to tema.idTema

The code
$dataProvider=new CActiveDataProvider('Tick');
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'idtick',         
        'idtema',  
        array(            
            'class'=>'CButtonColumn',
        ),
    ),
));



How can i show nomeTema in the grid ???

thxs !!!


Declare a relation in the Tick model e.g call it rtema. Then use rtema.nomeTema in the grid.

More info on relation here
http://www.yiiframew...de/database.arr

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   Joe Storm 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 17-April 10

Posted 05 July 2010 - 11:18 AM

I think you will have to get the dataProvider sorted out in the controller.. i.e joining the tables..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users