passing custom error message between models and controllers and views. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: passing custom error message between models and controllers and views. (/showthread.php?tid=52291) |
passing custom error message between models and controllers and views. - El Forum - 06-05-2012 [eluser]chubbypama[/eluser] I'm just new to codeigniter... I have a question about how to handle errors. I have a log in page that I've created, which includes the ability to create a new account. When someone tries to create a new account, the first thing i do is check if the user name already exists in my database. if it does, I'd like to be able to pass a user friendly error message to the view. (via the controller). Code: public function create_member() From what I've read, I can use either config files or session or global variables. It seems that global vars are a bad thing to do, based on my limited reading. Is this correct? The knee-jerk reaction I have to resolving this problem is to somehow create a global variable and pass that to the controller. Code: var $error_message; //this doesn't actually work. I still have to figure out why and then in the controller, do something like this: Code: $this->load->model('Membership_model'); I haven't gotten this prototype working yet because it's complaining about my get_error method in the model. It says that the variable $error_message hasn't been declared. But I would like some feedback / comments about how to handle 'expected' / 'potential' error messages and how to provide /pass the error message to the view. thanks. passing custom error message between models and controllers and views. - El Forum - 06-05-2012 [eluser]Cristian Gilè[/eluser] You can use form validation and callback. Check the user guide: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks passing custom error message between models and controllers and views. - El Forum - 06-05-2012 [eluser]chubbypama[/eluser] sweet! thanks! I'll look into that. |