title: CakePHP Differentiate parent and sub category
body: <p>I am trying to fetch list in categories and subcategories using same Model. Actually I want list for the select box as Optgroup having parent category and than options as part of optgroup as subcategory.</p>
  
  <p>My structure is..</p>
  
  <p>Category.id, Category.name, Category.parent_id
  Through the parent_id I am differentiating parent and child category. Now I wanna list format for the selectbox. I tried this code. Please help me out.</p>
  
  <pre><code>    $selectBox = array();
      $conditions =array('Category.status' =&gt; '1');
      $category_list = $this-&gt;Category-&gt;find('all',array('conditions'=&gt;$conditions, 'fields'=&gt;array('Category.id','Category.name','Category.parent_id')));
      foreach ($category_list as $category) {
          foreach ($category['Category'] as $subcategory) {
              $selectBox[$category['Category']['name']][]= array($subcategory['id'] =&gt; $subcategory['name']);
            }
      }
      pr($selectBox); exit;
  </code></pre>