Model instances with Active Record on CodeIgniter

Recently we developed at CodeKings a customized CMS to meet specific needs for a client. One of the requirements of this project was that we had to use the CodeIgniter MVC framework. Early in the programming, we feel the need to access methods of model’s objects to navigate the hierarchy of classes. Thus, in a control, for example, we could do this:

$user = $this->User_model->get_by_email('');
$group = $user->get_group();
echo $group->name; // Prints the name of the group the user belongs.

The problem is that in CodeIgniter, after calling the get method of Active Record class the value returned when generating query results is an array of StdClass’ instances (or an empty array on failure). In our case, it would be better to have a list of User_model. So, at first, we wrote the following helper (data_helper) to assist our work:
Continue reading “Model instances with Active Record on CodeIgniter”