problem fetching values from activeCheckboxList

Hello,

previous topic was about removing the default <br>, so far this problem is fixed. but i have troubles fetching the values form the checkboxes.

In the Model I try to add the values to the database in the afterSave() function. For debugging I used $this->Categories, but this will print nothing.

when I do a print_r($_POST) I see an array key Categories that contain the array with the categories id’s from the checkboxes.

Thank you in advance

The Categories will be saved in another table so I created a public $Categories in the top of the model file.




<?php

echo CHtml::activeCheckboxList(

    $daytrip,

    'Categories',

    CHtml::listData(

        Category::model()->findAll(),

        'IdCategory',

        'Category'

    ),

    array('template' => '<li>{input} {label}</li>',

        'separator' => '',

        'checkAll' => 'Alle rubrieken'

    )

);

?>



If you are using 1.0, make sure you list "Categories" in safeAttributes. If in 1.1, make sure you have a validation rule for "Categories".

i had some problems with duplicate names. the relation had the same name as the fields in the forms. so i changed the relation name.

For the sake of people like myself who are on a pretty steep learning curve with Yii right now could you explain in a little more detail what your problem was and how you solved it. I find the code examples in the forum to be extremely helpful.

Thanks,

doodle

I’m still learning Yii as well. Below you’ll find the code i used.

My problem was that after a post my $this->Categories was empty. b\Because I made a relation with the same. Solution change the relation name. I use rCategory, rCity etc as names for my relations.

The trick with afterFind() (see model) is to get the data so i can automaticly check the right checkboxes in the form.

hope you understand the problem and solution…

Model:

http://pastebin.com/f79ad2f5c

View:

http://pastebin.com/f1955fede

Controller:

http://pastebin.com/f36bf0b06

Thank you very much!

ps: I didn’t know about pastebin.com, could be very useful!

doodle