Hey guys! I’d love to hear what you think about this new plugin I’ve made. Do you think it is useful or not? Any ideas for improvement are welcome.
—Jonathon
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.
Advantages:
* No more calling get_instance() when you need to access the framework inside a model, library, helper, or view
* More concise syntax
* Support for multiple database connections
Requirements:
* CodeIgniter 1.5+
* PHP5+
Installation:
This is a plugin so no core hacking is required. Simply download modular_pi.zip and extract it into your application/plugins folder. Load it just like any other plugin.
How to use the Modularity Plugin
Views
# old way
$this->load->view('myview', $data);
# new way
View::show('myview', $data);
# old way
$pagetext = $this->load->view('myview', $data, TRUE);
# new way
$pagetext = View::parse('myview', $data);
Libraries
# old way
$this->load->library('mylibrary');
$this->library->do_something();
# new way
Libs::e('mylibrary')->do_something(); // the library automatically loads if needed
Models
# old way
$this->load->model('mydatamodel');
$this->mydatamodel->do_something();
# new way
Models::e('mydatamodel')->do_something(); // the model automatically loads if needed
Databases
# old way - default database
$this->load->database();
$query = $this->db->query($sql);
# new way
$query = DB::h()->query($sql); // the database automatically loads if needed
# old way - multiple database connections
$dbh1 = $this->load->database('db1', TRUE);
$dbh2 = $this->load->database('db2', TRUE);
$query1 = $dbh1->query($sql);
$query2 = $dbh2->query($sql);
# new way
$dbh1 = DB::h('db1')->query($sql);
$dbh2 = DB::h('db2')->query($sql);
Inside libraries, helpers, or views
# old way
$CI =& get_instance();
$CI->load->model('mymodel');
$CI->mymodel->do_something();
# new way
Models::e('mymodel')->do_something();
