Help With A Nested List Of Checkboxes For Model Insert/update

I must be missing something obvious here as everything in Yii is usually so easy!

I have my main model named ‘Program’, which has the related ‘Category’ and ‘SubCategory’ models/tables. These are MANY_MANY relations with intermediary tables/models ‘ProgramCategory’, and ‘ProgramSubCategory’ as well.

My goal is show a list of checkboxes which represent the Categories and then a NESTED list of checkboxes which show the SubCategories - which of course inserts/updates when saved ( I can do that part ).

Something like the following:

[x] Category 1

[ ] Category 2

–[ ] SubCategory 2a

–[x] SubCategory 2b

[ ] Category 3

and so on …

The categories and/or subcategories are also ‘required’ in the model - so they must also validate.

Could somebody point me in the right direction on this? I’d rather not use an extension - as I need to learn this.

Thank you for any help you can provide! =)

seems it’s a very common scanario, what i would do:

  1. add extra column to category model as parent_id and link sub-category relation back to the same model, so you eliminate sub-category model;

  2. use tree view to display the tree of your category and sub-category, to select [this part might be tricky] not so sure yet. i might use click event on each category to append category id into hidden field.

  3. to save , u said it.

Could you explain #1 a little further - I’m not quite grasping that (ie, eliminating sub->cat… model)

Thanks!

basically use one model for category and if category has sub-category it would refer to the same model;

so i don’t think you need ProgramSubCategory relation