I have used custom model
class Crud_work_model extends grocery_CRUD_Model { function get_list(){ $pj_id = $this->uri->segment(3); $sql = "SELECT * FROM tblworks WHERE projectid='$pj_id'"; $arr = $this->db->query($sql)->result(); return $this->works_multi_level_result($arr); } function db_insert($post_array) { $post_array['projectid'] = $this->uri->segment(3); $post_array['parentid']= $this->uri->segment(4);; parent::db_insert($post_array); } ....... ........ }
works_multi_level_result is my function, test ok
My controller :
<?php require_once APPPATH.'controllers/app.php'; class Works extends App{ public function __construct() { parent::__construct(); $this->load->database(); $this->load->library('grocery_CRUD'); } function manager($pj_id){ //echo $this->uri->segment(3); $crud = new grocery_CRUD(); $crud->set_subject('Công việc'); $crud->set_table('tblworks'); $crud->set_model('crud_work_model'); $crud->columns('name','beginonreality','reportdate'); $crud->unset_fields('tiedate','beginonplan','timevalueonplan','labour','timetieid','costonreality','datetieid','projectid','percent','parentid'); $crud->unset_edit_fields('tiedate','beginonplan','timevalueonplan','labour','timetieid','costonreality','datetieid','projectid','parentid'); $crud->set_relation('timetype','tbltimetype','name'); $crud->set_relation('timeunitid','tbltimeunit','name'); $crud->display_as('name','Tên công việc'); $crud->display_as('beginonreality','Bắt đầu'); $crud->display_as('reportdate','Ngà y báo cáo'); $crud->display_as('timevalueonreality','Thá»i gian thá»±c hiện'); $crud->display_as('timeunitid','ÄÆ¡n vị thá»i gian'); $crud->display_as('costonplan','Chi phÃ'); $crud->display_as('timetype','Loại thá»i gian'); $crud->display_as('parentid','Công việc cha'); $crud->display_as('percent','Tiến Ä‘á»™ hoà n thà nh (%)'); //$crud->add_action('Phân rã công việc', base_url()."assets/public/img/icon/settings.png','works/manager/add"); $output = $crud->render(); $output->title = "Công việc"; $output->content_title = "Công việc"; $output->sb = $this->_menu; $this->load->view('common/layout_view',$output); } } ?>
Every thing ok with add, edit, but with view :
Error Number: 1066
Not unique table/alias: 'jda11d612'
SELECT * FROM (`tblworks`) LEFT JOIN `tbltimetype` as jda11d612 ON `jda11d612`.`id` = `tblworks`.`timetype` LEFT JOIN `tbltimeunit` as jd6e1890b ON `jd6e1890b`.`id` = `tblworks`.`timeunitid` LEFT JOIN `tbltimetype` as jda11d612 ON `jda11d612`.`id` = `tblworks`.`timetype` LEFT JOIN `tbltimeunit` as jd6e1890b ON `jd6e1890b`.`id` = `tblworks`.`timeunitid` LIMIT 25
Filename: /home/dinhtrong/public_html/pm/models/grocery_crud_model.php
Line Number: 186
Left Join is repeated,
Is it a bug ? and what is slution for this problem
Thanks very much