在codeigniter中获取并显示下拉选择的值

时间:2016-04-19 07:51:38

标签: codeigniter

我想从数据库中获取所选值并将其显示在codeigniter start函数中,但显示错误。

控制器:

form_dropdown()

查看:

$type = array(
'options' => array(
  'section'       => 'Section',
  'transaction' => 'Transaction',
  'document'      => 'Document'
  ),
'attributes' => array(
  'class' => 'form-control'
  )
);

Screenshot

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

控制器:

$this->data['type']  =  array(
        'name'         => 'type_value',
        'attributes'   => 'class="form-control"',
        'value'        => (isset($database_type_value) && trim($database_type_value)) ? $database_type_value: $this->input->post('type_value',TRUE),   //$database_type_value - value from database
        'options_list' => array(
            'section'        => 'Section',
            'transaction'    => 'Transaction',
            'document'       => 'Document'
        ),
);

查看:

<?php echo form_dropdown($type['name'],$type['options_list'],$type['value'],$type['attributes']);?>