I want to load only main categories(not sub-categories) name in drop down list. i have tried enough but could not succeed. There are numbers of answer on this site and I tried to solve my problem in that way but can't. The category table is given below, it is same as on cakephp docs in Tree.
categories table attribute
id | parent_id | lft| rght |name |
i tried these techniques given on following links How to populate drop-down list with database values in CakePHP
full code of controller to create category is given below.
if ($this->request->is('post')) {
$this->Category->create();
if ($this->Category->save($this->request->data)) {
$this->Session->setFlash(__('Category has been saved.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to add Category.'));
}
else
$categories = $this->Category->find('list');
$this->set(compact('categories'));
return $this;
}
code of category.ctp is
<?php echo $this->Form->create('Category'); ?>
<fieldset>
<legend><?php echo __('Add Category'); ?>
</legend>
<?php
$form->input('id');
// echo $this->Form->input('id');
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
now please suggest me solution to load data in drop down list.