Example #1
bschaeffer'sanswer to this question – in his last example:
$this->load->model('table');
$data = $this->table->some_func();
$this->load->view('view', $data);
How do you handle this when 'table' doesn’t exist?
Example #2
try {
$this->load->model('serve_' . $model_name, 'my_model');
$this->my_model->my_fcn($prams);
// Model Exists
} catch (Exception $e) {
// Model does NOT Exist
}
But still after running this (obvously the model doesn’t exist – but sometimes will) it fails with the following error:
An Error Was Encountered
Unable to locate the model you have specified: serve_forms
I am getting this function call by:
1) Getting some JSON:
"model_1:{"function_name:{"pram_1":"1", "pram_2":"1"}}
2) And turning it into the function call:
$this->load->model(‘serve_’ . “model_1”, ‘my_model’);
3) Where I call:
$this->my_model->function_name(pram_1=1, pram_2=1);
SOLUTION
The problem lies in the fact that CodeIgniter’s show_error(...) function displays the error then exit; … Not cool … So I overrode: model(...) -> my_model(..) (you’ll get errors if you just override it) and removed the show_error(...) because for some reason you can’t override it – weird for Codeigniter). Then in my_model(...) made it throw an Exception
My personal opinion: the calling function should
returnwhere show_error returns
show_error("message");FALSE— that or
you could take out theexit;– and makeshow_error(...)
overridable
You can see if the file exists in the models folder.