Relational Active Record for multicheckbox

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 ?

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.

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.