A Magical CodeIgniter Super Object

Recently Militis reminded me of a “trick” to automatically load items from the CodeIgniter super-object. Of course, you should determine for yourself if this functionality is needed and is worth the performance loss. We’re now using this in Ion Auth if you want to see it in action.

Just add the following method to your library class

public function __get($var)
{
	return get_instance()->$var;
}

And then you can access and CI items through the $this object like so

$this->load->library('email');

Let's work together.

If you're interested in working together email me at ben@benedmunds.com with details and I'll be happy to connect.


Find me on ...