Cakephp - creating a field with multiple selection fields

I need to create a field to select multiple items using helper forms in cakephp. The values ​​in the field will be populated from the table that received the HABTM for the current model.

What is the best way to implement this?

+4
source share
1 answer

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')); 
+5
source

Source: https://habr.com/ru/post/1448056/


All Articles