Codeigniter Grocery Crud extend set_relation() function? Codeigniter Grocery Crud extend set_relation() function? codeigniter codeigniter

Codeigniter Grocery Crud extend set_relation() function?


I know my response is some what dated and probably no use to the OP now, but I'm guessing there are many people who might be looking at this post for inspiration to their own set_relation problems. I propose a more simple solution to this... (in fairness to Idham I don't know when the 4th param of set_relation() became available.)

...$state = "AZ"; // or however you get the state you want to filter by$crud->set_relation('officeCode','offices','city', 'officeCode IN (SELECT officeCode FROM offices WHERE state='.$state.')');...

Voila! True grocery_CRUD awesomeness!


$crud->set_relation('officeCode','offices','city',array('country' => 'Arizona'));

This works fine as for version v.1.2 or later


I think you need this:

function employees_management(){    $crud = new grocery_CRUD();    $crud->set_theme('datatables');    $crud->set_table('employees');    // add this line    $crud->callback_edit_field('officeCode',array($this,'_call_back_offices'));    $crud->callback_add_field('officeCode',array($this,'_call_back_offices'));    $crud->display_as('officeCode','Office City');    $crud->set_subject('Employee');    $crud->set_relation('officeCode','offices','city');    $output = $crud->render();    $this->_example_output($output);}function _call_back_offices(){    $this->load->model('user_model'); // your model    $data = $this->user_model->getYou('offices','officeCode, city', "state = '".$this->session->userdata('state')."'"); // iam using session here    $hasil ='<select name="officeCode">';    foreach($data as $x)    {        $hasil .='<option value="'.$x->officeCode.'">'.$x->city.'</option>';    }    return $hasil.'</select>';}example user_model code:function getYou($tabel,$field = '*', $cond =''){    $this->db->select($field);    $this->db->from($tabel);    if(!empty($cond)) $this->db->where($cond);    return $this->db->get()->result();}