Reputation: 38402
is there a built-in helper that creates a drop-down/select of numbers from start to end like 1 to 50
<select>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
I dont want to create a custom helper or use for loop
Upvotes: 2
Views: 2136
Reputation: 6047
Just do:
$this->Form->input('numbers', array('type' => 'select', 'options' => range(0, 50)));
if you need fomething more complicated like like number starting from 5 or so do:
$options = range(5, 20);
$this->Form->input('numbers', array('type' => 'select', 'options' => array_combine($options, $options)));
Upvotes: 2
Reputation: 11575
There is no "magical cakephp way" to do this. The best way is to implement this is in the controller function you put:
$numbers = array();
for($i = 1; $i < 50; $i++) {
array_push($numbers, $i);
}
$this->set('numbers', $numbers);
Then in the view:
$this->Form->input('numbers', array('type' => 'select', 'options' => $numbers));
I am sure there are other methods, but this is by far the simplest.
UPDATE: If you prefer you can use:
foreach(range(1, 50) as $number) {
array_push($numbers, $number);
}
Upvotes: 3