Form::Cakephp Helper

Asked

Viewed 53 times

0

As if I do a for return in this options 48 weeks?

<?= $this->Form->input('Semanas', array(
      'options' => $semanas,
      'empty' => '(choose one)'
 )); ?>
  • You could show your controller ?

  • Do you want to show these weeks how? In numbers same?

  • Wanted to show "1 week", "2 weeks", etc..

  • Should the answer be saved as the number of weeks is also that? A option thus <option value="1 semana">1 semana</option>. Would that be?

  • Yes, the answer is the number, and the argument would be the number + week(s)

2 answers

0

In the Controller, you might have something like that, assuming your action be the very one index():

public function index() {
    $semanas = array();

    for ($i = 1; $i < 49; $i++) {
        $semanas[$i] = "$i semana" . ($i > 1 ? "s" : "");
    }

    $this->set('semanas', $semanas);
}

And the View remains as is, so the value of each option will be numerical corresponding to the number of the week and the text as you mentioned: 1 week, 2 weeks, 3 weeks...

0

You can create a for popular one array, both in the controller as measured voi, and in the view as such:

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)'
)); ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.