GroceryCRUD:如何设置字段下拉列表

时间:2014-12-27 07:51:49

标签: php mysql grocery-crud

我只是用GroceryCRUD编码, 这是我的数据库:

  

a_guest_data

guest_no
register_date 
name 
gender 
birthday 
address 
city 
country 
phone 
email 
ref 
status 
date_modified
  

a_table_data

id_table 
tbl_name 
group_name 
status 
seat 
party_date 
locked 
pos_tbl 
date_modified
  

a_table_group

id_table 
guest_no 
priority

这是我的控制器代码:

public function guest_management()
{
    $crud = new grocery_CRUD();

    $crud->set_table('a_guest_data');
    $crud->set_subject('Guest');
    $crud->set_relation_n_n('tables', 'a_table_group', 'a_table_data', 'guest_no', 'id_table', 'tbl_name');
    $crud->unset_columns('register_date','layout_no', 'date_modified', 'ref');

    $crud->fields('name', 'register_date', 'gender', 'birthday', 'tables', 'address', 'city', 'country', 'phone', 'email', 'ref', 'status' );


    $crud->field_type('country','dropdown', array('Indonesia' => 'Indonesia', 'Others' => 'Others'));
    $crud->field_type('gender','dropdown', array('Male' => 'Male', 'Female' => 'Female'));
    $crud->field_type('status','dropdown', array('1' => '1', '2' => '2'));

    $output = $crud->render();

    $this->_example_output($output);
}

我有这样的形式 enter image description here enter image description here

在字段表中,我想设置只能选择1个表的下拉字段(事实是,现在在表格中,我可以选择多个选项表。*参见图片,我选择表1, 45,6,34)。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

此行为是由于您的数据库结构所致。如果只需要一个表值,则需要将数据库结构设置为“ 1-n数据库关系

1-n database relation

Documentation for about database relationships

您想要用杂货杂货术语实现的是set_relation。

set_relation的语法:

void set_relation( string $field_name , string  $related_table, string $related_title_field  [, mixed $where [, string $order_by ] ] )

Docs for set_relation

最后,您的priority字段也将在表a_guest_data

相关问题