views:

43

answers:

2

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

+3  A: 

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);
}
cdburgess
+1  A: 

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)));
Nik
hope this works
Web Developer