![]() |
Models - returns array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Models - returns array (/showthread.php?tid=44904) |
Models - returns array - El Forum - 08-30-2011 [eluser]xoRiZ[/eluser] I've come to use this very frequently, as I've noticed in all my models, I want my functions to return 3 things. 1) Did it error? 2) Message (erroneous or not) 3) Result set In retrospect, perhaps this should be an object, instead of an array.. But oh well. Essentially, you pass this function( (bool) Error, (string) Message[, (mixed) Result]) It will log if there's an error, and include the query. If you pass anything as the result in the event of an error, you can log it, without it being displayed to the user. I'm thinking for multilingual support, you would pass the language key as the message and parse it in this function and to the user. return_helper.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Example usage: Model: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Controller Code: class Agent extends MY_Controller { Some of this code has had large snippets removed .. But you should be able to draw the general idea behind the use of the array. I'm not sure if doing this is in bad taste or not, but I welcome alternatives, if it is. |