php - Error "reporting" in a model -


i'm thinking of returning errors ocurred inside model, 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 empty!');           $this->set_error('dev','// db error in full');           return false;      } } 

this way can treat them on controller:

class data extends ci_controller {      public function index(){           $this->load->model('data');           $data = $this->data->data();           if(!$data)           // send $this->data->get_errors() user , logs           else               // send $data view      } } 

is idea? potential drawbacks, , there better way go treating db operations/data validation errors?

new "evidence": http://www.firehed.net/mvc-model-data-validation

crud model. better have model throw exception controller. controller catches , whatever needs done.

model:

class data_model extends ci_model {       public function getdata($id){         if( /* worthy of error */) {             throw new exeption('your db seems empty!');         }         } } 

controller:

class data extends ci_controller {     public function index(){         $this->load->model('data_model','', 'data');         try {             $data = $this->data->getdata();         } catch (exception $e) {             // send $e->getmessage() user , logs         }         // send $data view     } } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -