Form :: Helper cakephp [duplicate]

0

How do I make a for return in this options 48 weeks?

<?= $this->Form->input('Semanas', array(
      'options' => $semanas,
      'empty' => '(choose one)'
 )); ?>
    
asked by anonymous 14.04.2015 / 19:51

2 answers

0

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>     
14.04.2015 / 20:32
0

You can create a for a popular array , both in the controller and voi, and in the view like this:

Thus:

<?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)'
)); ?>
    
14.04.2015 / 21:48