Hi all,
I have 2 tables: category and product as below:
Category: id, name
Product: id, category_id, name (category_id is the foreign key to category table)
When I added a new record at product page, my expected: category_id field is a selection box (refer to category table)
Anyone can help me this issue?
Thank you so much! ( sorry for my poor English)
My code as below:
public function category(){
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('category');
$crud->columns('name');
$crud->fields('name', 'has_parent');
$crud->unset_print();
$crud->unset_export();
$crud->required_fields('name');
$crud->set_relation('id', 'product','category_id');
$output = $crud->render();
$this->_example_output($output);
}
public function product(){
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('product');
$crud->columns('name', 'code', 'price', 'category_id', 'description');
$crud->unset_print();
$crud->unset_export();
$crud->required_fields('name', 'code', 'price', 'category_id');
$output = $crud->render();
$this->_example_output($output);
}
