I'm looking for proper way to organize 'Result object classes' in CodeIgniter. These classes are usualy used in models as described in documentation:
You can also pass a string to result() which represents a class to instantiate for each result object (note: this class must be loaded)
$query = $this->db->query("SELECT * FROM users;");
foreach ($query->result('User') as $row)
{
echo $row->name; // call attributes
echo $row->reverse_name(); // or methods defined on the 'User' class
}
So, where to put 'User' class and is there any 'offical' way how to load it?
Try using a library.
Place your class in the application/libraries folder, then use the loader to load it:
$this->load->library('user');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With