How do I make a for return in this options 48 weeks?
<?= $this->Form->input('Semanas', array(
'options' => $semanas,
'empty' => '(choose one)'
)); ?>
How do I make a for return in this options 48 weeks?
<?= $this->Form->input('Semanas', array(
'options' => $semanas,
'empty' => '(choose one)'
)); ?>
In Controller , you can have something like this, assuming your action is itself index()
:
public function index() {
$semanas = array();
for ($i = 1; $i < 49; $i++) {
$semanas[$i] = "$i semana" . ($i > 1 ? "s" : "");
}
$this->set('semanas', $semanas);
}
And View remains as it is, so the value of each option will be numeric corresponding to the number of the week and the text as you mentioned: 1 week, 2 weeks, 3 weeks ...
p>You can create a for a popular array , both in the controller and voi, and in the view like this:
<?php
$semanas = array();
for($i=1;$i<49;$i++){
$semanas["{$i} semanas"] = "{$i} semanas";
}
echo $this->Form->input('Semanas', array(
'options' => $semanas,
'empty' => '(choose one)'
)); ?>