Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put and how to load result object class in Codeigniter?

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?

like image 618
sasa Avatar asked Sep 17 '12 11:09

sasa


1 Answers

Try using a library.

Place your class in the application/libraries folder, then use the loader to load it:

$this->load->library('user');
like image 167
Silviu G Avatar answered Oct 30 '22 08:10

Silviu G