$select = array(
'Select Customer' => 'Select Customer',
$customer_id
);
echo form_dropdown(array('name' =>'customer_id' ) , $select);
我想添加'选择客户'在选择之前,但有" 0"在下拉列表中。如何删除它?
答案 0 :(得分:2)
https://www.codeigniter.com/user_guide/helpers/form_helper.html#form_dropdown
当您可以使用控制器和型号更新问题时。
在您的控制器或型号代码中,您可能会[]
导致optgroup显示。
代码示例
$this->load->helper('form');
$customer[] = array(
'0' => 'Select Customer',
'1' => 'John',
'2' => 'Matthew',
'3' => 'Luke'
);
$data['customer'] = $customer;
$this->load->view('someview', $data);
查看
<?php echo form_dropdown('name', $customer, '', array('class' => 'form-control'));?>
删除
[]
会删除optgroup0
代码示例
$this->load->helper('form');
$customer = array(
'0' => 'Select Customer',
'1' => 'John',
'2' => 'Matthew',
'3' => 'Luke'
);
$data['customer'] = $customer;
$this->load->view('someview', $data);
查看
<?php echo form_dropdown('name', $customer, '', array('class' => 'form-control'));?>