Cakephp-create a multi select form field

cakephp, cakephp-2.0, helper

Solution

In your ctp file:

echo $this->Form->input('Category', array(
    'multiple' => 'multiple',
    'type' => 'select',
));

in your action:

$cats = $this->Category->find('all');
foreach ($cats as $category) {
    $categories[$category['Category']['id']] = $category['Category']['title'];
}
$this->set(compact('categories'));

Problem

I need to create a multi select form field using form helpers in cakephp.The values in the field will get populated from a table which had got a HABTM to the current model. What is the best way to implement this?

Original source