如何在codeigniter购物车中设置数量更新的最大值

时间:2017-10-25 07:37:58

标签: php codeigniter

<?php echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], max=> $item['price'] ' type="number"  min="1" value="1" )'; ?>

如何设置最大值,它会显示语法错误,意外&#39; =&gt;&#39; (T_DOUBLE_ARROW)

1 个答案:

答案 0 :(得分:1)

最简单的方法是传递关联数组,

<?php 
      echo form_input(
             array(
               'name'=> 'cart[' . $item['id'] . '][qty]', 
               'type'=>"number",
               'min'=>1,
               'max'=> $item['price'],
               'value'=> $item['qty'], 
              ) 
      ); 
?>

您仍然可以更正现有的

<?php 
    echo form_input(
              /*name*/
             'cart[' . $item['id'] . '][qty]',  

             /* value */
             $item['qty'],                       

             /* other attributes as string */
             'max="'.$item['price'].'" type="number" min="1"'           
     ); 
?>

来自: https://www.codeigniter.com/userguide3/helpers/form_helper.html

  

form_input([$data = ''[, $value = ''[, $extra = '']]])

     

参数:

$data (array)   – Field attributes data
$value (string) – Field value
$extra (mixed)  – Extra attributes to be added to the tag 
                  either as an array or a literal string