如何使用GroceryCrud添加自定义下拉列表?我有以下mysql表:
CREATE TABLE IF NOT EXISTS `clients` (
`clientId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`clientName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`cif` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
`type` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`clientId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
以下代码显示功能:
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('clients');
$crud->set_subject($this->lang->line('tpv_clients'));
$crud->display_as('clientName', $this->lang->line('tpv_client_name'));
$crud->display_as('cif', $this->lang->line('tpv_client_cif'));
$crud->display_as('address', $this->lang->line('tpv_client_address'));
$crud->display_as('type', $this->lang->line('tpv_client_type'));
$crud->columns('clientName','address','type');
$crud->required_fields('clientName', 'cif', 'type');
$output = $crud->render();
字段“type”应该只包含两个值:“A”或“B”。我需要一个包含这两个值的下拉组合。我试过这段代码
$crud->field_type('type','dropdown',array('1' => 'A', '2' => 'B'));
但它不起作用。
答案 0 :(得分:2)
我想你只需要这个:
$crud->field_type('type','dropdown',array('A' => 'A', 'B' => 'B'));
有关field_type方法的详情,请查看:http://www.grocerycrud.com/documentation/options_functions/field_type
答案 1 :(得分:0)
您还可以将列定义为ENUM:
type
ENUM(' A',' B')COLLATE utf8_unicode_ci DEFAULT NULL,