Pass model name as a parameter in function and use its methods like "$this-> $model_name->method()" codeigniter Pass model name as a parameter in function and use its methods like "$this-> $model_name->method()" codeigniter codeigniter codeigniter

Pass model name as a parameter in function and use its methods like "$this-> $model_name->method()" codeigniter


When you load the model you can assign it a generic name that you can then use to reference that model in your code.

function fill_dropdown($model_name, $id, $table_name, $field){    $this->load->model($model_name, 'myModel');    $row = $this->myModel->get_all_id($id,$table_name);    foreach ($row->result() as $val)     return "<option value='". $val->$field."'>".$val->$field."</option> \n" ;}

See the "Loading a Model" section of the user guide.