Yii Framework Forum: Relational Active Record for multicheckbox - Yii Framework Forum

Jump to content

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

Relational Active Record for multicheckbox many to many relation with extra parameters in table Rate Topic: -----

#1 User is offline   ignis 

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

Posted 09 July 2010 - 06:59 AM

Hello,

I'll try to describe the main problem.

I have tree tables in my acl system, for example:

roles
id
role_title

menu
id
menu_title

rolemenu
role_id
menu_id
can_view
can_create
can_update
can_delete

I wannt to fill these fields automatically by relational active record help, but I dont know how it's possible.

And when I create new role item I can choise what user can do in different menus (CRUD).

Menu form:


<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

And the menus with checkboxes:
 $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'menu-grid',
    'selectableRows' => 2,
	'dataProvider'=>$dataProvider,
	/*'filter'=>$model,*/
	'columns'=>array(
            'id',
            'title',
             array(
                'class' => 'SCheckboxColumn',
                'checkBoxHtmlOptions' =>
                    array(
                        'checked' => 'checked',
                    ),
                'header' => 'View',
                'id'     => 'roles_action_view',
                'value'  => '$data->id',
            ),
            array(
                'class' => 'SCheckboxColumn',

                'checkBoxHtmlOptions' =>
                    array(
                        'checked' => 'checked',
                    ),
                'header' => 'Create',
                'id'     => 'roles_action_create',
                'value'  => '$data->id',
            ),
            array(
                'class' => 'SCheckboxColumn',
                'checkBoxHtmlOptions' =>
                    array(
                        'checked' => 'checked',
                    ),
                'header' => 'Update',
                'id'     => 'roles_action_update',
                'value'  => '$data->id',
            ),
            array(
                'class' => 'SCheckboxColumn',
                'checkBoxHtmlOptions' =>
                    array(
                        'checked' => 'checked',
                    ),
                'header' => 'Delete',
                'id'     => 'roles_action_delete',
                'value'  => '$data->id',
            ),

        ),
    ));


I have set relations

in menu model:
public function relations()
	{
		return array(
            'module' => array(self::HAS_MANY, 'Modules', 'id'),
            'role'   => array(self::MANY_MANY, 'Roles',
                'rolemenu(role_id, menu_id)'),
		);
	}

In roled model:
public function relations()
	{
		return array(
            'menu'=>array(self::MANY_MANY, 'Menu',
                'rolemenu(role_id, menu_id)'),
		);
	}


All menu information yii saves, but no checkbox selection apears in database.

Is there possible to do this thing automatically in yii or I must write in role controller insert or update action loop to write all checkboxes ?
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 09 July 2010 - 07:20 AM

Yii has an rbac already implemented.

I guess that for you can be much more faster and confortable read the documentation of rbac and use this one instead of implement your own system.


It can suite every situation you need.
0

#3 User is offline   ignis 

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

Posted 09 July 2010 - 07:28 AM

Yes I know about rbac, but I have still the same question, becose not even in this place I wannt to use this method, thats why I am asking.

Thanks for answer.
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