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');

Get In Touch.

If you'd like to get in touch, you can reach me at ben@benedmunds.com.


Find me on ...