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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀