Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Modularity in CodeIgniter PHP5

compwright edited this page · 13 revisions
Clone this wiki locally

DEPRECATED: This plugin has been replaced by loaders on

Plugin Introduction

I've become sick and tired of CodeIgniter's $this-centeredness and I want to use static PHP5 classes to access core CodeIgniter objects such as libraries, models, view, and db. So, I have written a very simple set of wrapper classes.


  • No more calling get_instance() when you need to access the framework inside a model, library, helper, or view
  • No more manual loading of libraries, models, or databases
  • More concise syntax
  • Support for multiple database connections


  • CodeIgniter 1.5+
  • PHP5+

Installation: This is a plugin so no core hacking is required. Simply download and extract it into your application/plugins folder. Load it just like any other plugin.

How to use the Modularity Plugin


# Display a view -- old way
$this->load->view('myview', $data);
# new way
View::show('myview', $data);

# Load a view into a string variable -- old way
$pagetext = $this->load->view('myview', $data, TRUE);
# new way
$pagetext = View::parse('myview', $data);


# Do something with a library -- old way

# new way
Libs('mylibrary')->do_something();  // the library automatically loads if needed


# Fetch data with a model -- old way

# new way
Models('mydatamodel')->do_something();  // the model automatically loads if needed


# Query a database -- old way (default database)
$query = $this->db->query($sql);

# new way
$query = DB()->query($sql);  // the database automatically loads if needed

# Query a database -- old way (multiple connections)
$dbh1 = $this->load->database('db1', TRUE);
$dbh2 = $this->load->database('db2', TRUE);
$query1 = $dbh1->query($sql);
$query2 = $dbh2->query($sql);

# new way
$query1 = DB('db1')->query($sql);
$query2 = DB('db2')->query($sql);

Inside libraries, helpers, or views

# old way
$CI =& get_instance();

# new way -- no calling get_instance()!
Something went wrong with that request. Please try again.