dqjl0906 2016-07-11 08:19
浏览 42
已采纳

CakePHP 3:在select |中动态创建选项 表格助手

I want to generate select input field like

<select name="quantity">
  <option value="">Quantity</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

where option is generated dynamically.

There is a stock column which contains int value. I want to generate options as much as value in stock. Ex: If stock value is 5 then option will be from 1 to 5.

I can generate select input field by

$this->Form->select('quantity', [1,2,3,4,5], ['empty' => 'Quantity'])

But here options generated will of 5 length. I want it to be generated as per the value in stock column.

  • 写回答

3条回答 默认 最新

  • dswg47377 2016-07-11 11:32
    关注

    First set your $stack variable value in controller using set (Simple way) :

     $this->set('stack', $stack);
    

    use that variable like this in your view:

    $options = range(1,$stack);
    
     $this->Form->select('dropdown name', $options, ['empty' => 'Quantity'])
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的