Yii Framework Forum: using relations with CGridView - Yii Framework Forum

Jump to content

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

using relations with CGridView Rate Topic: -----

#1 User is offline   ignis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-April 10
  • Location:Lithuania - Vilnius

Posted 13 July 2010 - 05:28 AM

Hi,

I'll describe the problom as clearly as I can.

I have activeDataProvider:

$dataProvider=new CActiveDataProvider('Menu', array(
    'criteria'=>array(         
       'with' => array('roles'),
    ),
));


then I'am using CGridView with checkbox:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'menu-grid',
'selectableRows' => 2,
'dataProvider'=>$dataProvider,
'columns'=>array(
        'id',
        'title',
         array(
            'class'    => 'SCheckboxColumn',
            'header'   => 'View',
            'name'     => 'Roles[Actions][can_view]',
            'id'       => 'roles_action_can_view',
             'value'    => '$data->id',
            'checkBoxHtmlOptions' =>
                array('checked' => $data->roles->can_view,),
        ),
    ),
));


Then in Menu Model relations:

return array(
        'roles' => array(self::HAS_MANY, 'Rolesmenus', 'menu_id'),
    );


and in Rolesmenus Model relations:

return array(
        'menu' => array(self::BELONGS_TO, 'Menu', 'menu_id'),
    );


So, I cant access $data->roles->can_view variable, when I var_dump all $data object I can see these atributes in _atributtes private array but I cant them access through CGridView.

Any ideas??
0

#2 User is offline   PoL 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 506
  • Joined: 05-November 08
  • Location:Buenos Aires, Argentina

Posted 13 July 2010 - 08:04 AM

Try with a php expression:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'menu-grid',
'selectableRows' => 2,
'dataProvider'=>$dataProvider,
'columns'=>array(
        'id',
        'title',
         array(
            'class'    => 'SCheckboxColumn',
            'header'   => 'View',
            'name'     => 'Roles[Actions][can_view]',
            'id'       => 'roles_action_can_view',
             'value'    => '$data->id',
            'checkBoxHtmlOptions' =>
                array('checked' => '$data->roles->can_view',), // <<-- Here!!!
        ),
    ),
));

Don't say what you think, think what you say
The problem is communication! Excess of communication!
0

#3 User is offline   ignis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-April 10
  • Location:Lithuania - Vilnius

Posted 26 July 2010 - 10:11 AM

Well, the problem was in sql. I solved problem in sql and write this model without yii relations, because in this case I must write:

SELECT t.* FROM ( SELECT * FROM table2 ) t2 LEFT JOIN table1 ON ...


Anyway, thanks for replay ;)
0

Share this topic:


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

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