Indent For Nested Checkboxes

Hi there!

I have many-many relation between Product and Category models as well as nested categories (there is a field category_id in tbl_category in my DB to specify this relation). In my views/product/_form.php partial I have all directories listed with checkboxes to choose which one (or several) user want to relate product to.

Now about the problem. Yii have awesome method called checkBoxList() that suits me well, but I want to make some indentation for nested checkboxes. What way of implementig this will be the best, without too many queries to database?

What I have now is:

foreach(CHtml::listData(Category::model()->findAll('category_id = 0'), 'id', 'title') as $id => $title) 


  echo CHtml::checkBox($id, /* Here I need to invoke ProductCategory model to get this checkbox checked/unchecked /*);

  // printing Checkboxe's label here

  if(Category::model()->findAll('category_id = '.$id))


    // Nested checkbox here, with some indent



It will work, I suppose, but I feel that it’s not the best way to implement this like that, am I wrong?

Thanks in advance.

This extension may help you.

Regarding presentation, just use CSS and you’re good. No need to worry with indenting the HTML.

Thank you so much! That worked great!