I’m thinking of returning errors that ocurred inside a model, the following way:
class Data extends CI_Model {
private $errors_list
private function Set_error($control,$error_string){
$this->errors_list[][$control] = $error_string;
}
public function Get_errors($control){
// logic
return $errors_array;
}
public function Data(){
// error happens
$this->set_error('User','Your db seems to be empty!');
$this->set_error('Dev','// DB error in full');
return false;
}
}
This way I can treat them on the controller:
class Data extends CI_Controller {
public function index(){
$this->load->model('Data');
$data = $this->data->data();
if(!$data)
// send $this->data->get_errors() to user and logs
else
// send $data to view
}
}
Is that a good idea? What are the potential drawbacks, and is there a better way to go about treating db operations/data validation errors?
New “evidence”: http://www.firehed.net/mvc-model-data-validation
CRUD is for the model. What would be better is to have the model throw an exception back to the controller. The controller catches it and does whatever needs to be done.
Model:
Controller: