php - Cakephp DropDown with Parent and child -


to begin here example of want achieve using cake-php way create combo-box populated 2 tables categories , subcategories.

-- category1  --- subcategory1  --- subcategory2  --- ... -- category2  --- subcategory1  --- subcategory2  --- ... 

in controller tried list of categories subcategories using code bellow didn't work , returning list of subcategories:

$this->set('category',($this->category->subcategory->find('list'))); 

here associations i'm using between models:

category model

<?php  class category extends appmodel{          public $hasmany=array(                  'subcategory'=>array(                         'classname'=>'subcategories',                      )              );  } 

subcategory model

<?php  class subcategory extends appmodel{       public $belongsto=array(          'category'=>array(                 'classname'=>'categories',                 'foreignkey'=> 'categories_id'             )          );   } 

i hope question clear , lot.

$options = array(); foreach($this->category->find('all') $key => $category) {      $options[$category['category']['name']] = $this->category->subcategory->find('list') } $this->set('category', $options);  

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -