0
votes

I am a newbie to YII.

I have generated a crud form for contactlist. I have also generated checkboxes using widget for "manage contactlist". So, this checkbox code was written in admin.php page. All I want to do is saving these checked values now to database on clicking some submit button in "manage contactlist.

How can I achieve this?

3

3 Answers

0
votes

you can choose type of checkbook field in database as (tiny-int) and in the form use this code

<div class="row"> <?php echo $form->labelEx($model,'Active'); ?> <?php echo $form->checkBox($model,'Active'); ?> <?php echo $form->error($model,'Active'); ?> </div>

0
votes

This will be useful if you want to store it as an array.

0
votes

You will need 3 things here 1) A checkbox that picks out the IDs using CCheckBoxColumn and then 2) Ajax call to pick out the data from it. Take a look at CHtml:AjaxButton for more. 3) A controller method to process the POST values sent via the Ajax call.

In your Gridview widget:

<?php $gridWidget = $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'name-your-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        array(
            'class'=>'CCheckBoxColumn',
            'id' => 'example-check-boxes',
            'selectableRows'=>100 //Max Selectable number of rows           
            ),
..... ?>

Later in your Admin view's AJAX call:

'data'=> 'js:{theIds : ($.fn.yiiGridView.getChecked("name-your-grid","example-check-boxes").toString())}',