Yii Framework Forum: problem fetching values from activeCheckboxList - Yii Framework Forum

Jump to content

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

problem fetching values from activeCheckboxList Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 28 October 2009 - 12:47 PM

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'
    )
);
?>

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,871
  • Joined: 04-October 08
  • Location:DC, USA

Posted 29 October 2009 - 06:03 AM

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".
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 29 October 2009 - 08:04 AM

View Postqiang, on 29 October 2009 - 06:03 AM, said:

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.
0

#4 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 29 October 2009 - 08:55 AM

View Postbas_vdl, on 29 October 2009 - 08:04 AM, said:

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
Check out myYii powered website
0

#5 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 29 October 2009 - 09:00 AM

View Postgot 2 doodle, on 29 October 2009 - 08:55 AM, said:

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
1

#6 User is offline   got 2 doodle 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-December 08
  • Location:Beautiful Nova Scotia, Canada

Posted 29 October 2009 - 09:45 AM

View Postbas_vdl, on 29 October 2009 - 09:00 AM, said:

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
Check out myYii powered website
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