Marc
Marc

Reputation: 483

Cakephp adding option field with array values

I am trying to create a drop down menu (option) and to fill this drop down i have sent an array list to the view:

            $country = $this->country_list;

            $this->set(compact('country'));

Now my question is does cake have a buildin method for me to set an input field using ($this->Form->input()) with the data of the array list?

Upvotes: 0

Views: 1173

Answers (2)

Cocuba
Cocuba

Reputation: 372

take this example

$sizes = array(
        's' => 'Small',
        'm' => 'Medium',
        'l' => 'Large'
);

echo $this->Form->input('size', array('options' => $sizes, 'default' => 'm'));

Upvotes: 1

Brian Kerr
Brian Kerr

Reputation: 401

In the controller, set the value

$this->set('countries', $this->Country->find('list', array('fields' => 'Country.name')));

To show the dropdown box in the view

$this->Form->input('country_id');

Upvotes: 1

Related Questions