A core object loader and accessor for CodeIgniter
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Loaders is a collection of loaders and accessors for CodeIgniter's core objects.

After you write enough CodeIgniter applications, writing $this and manually loading stuff gets old. Loaders is an easier, globally-accessible way to access core CodeIgniter objects such as libraries, models, view, and db.

Originally conceived as a plugin called "Modularity", this has been reborn as a CodeIgniter 2.0-compatible helper.


  • Auto-load libraries, models, databases
  • Eliminates need to call get_instance() when you need to access framework objects inside a model, library, helper, or view
  • Concise syntax
  • Supports multiple database connections
  • Requires PHP5 & CodeIgniter 1.5+


Install and load Loaders as you would any other CodeIgniter helper.

Or, use the Sparks package installer:

php tools/spark install -v0.0.1 loaders



The normal way to load and display a view is like so:

$this->load->view('myview', $data);

With the View loader, do it this way:

Views::show('myview', $data);

Or if you want to return a string instead of outputting the view, do this:

$pagetext = Views::parse('myview', $data);


The old way to load libraries was like this:


With the library loader, you can just do this:

Library('mylibrary')->do_something(); // the library automatically loads if needed


To fetch data with a model, we used to do this:


Now, with the model loader, it works like this:

Model('mydatamodel')->do_something(); // the model automatically loads if needed


The old way to run a query on the default database connection:

$query = $this->db->query($sql);

Using the database loader, it is easier:

$query = Database()->query($sql); // the database automatically loads if needed

Maybe you have multiple connections?

$query1 = Database('db1')->query($sql);
$query2 = Database('db2')->query($sql);

Global access

These loaders work anywhere in exactly the same way, including libraries, helpers, and views.

Previously, you had to get an instance of the $CI object to work with, which can be a drag:

$CI =& get_instance();

Now you don't have to call get_instance() anymore!