Extended CodeIgniter Loader Library

I’ve been trying to make contributions wherever I can to CI and one handy thing I’ve been using is an extended CI Loader Library. It adds 2 features:

1. The ability to alias auto-loaded models and libraries.
2. The ability to load a model or library from another CI application on the same server.

Here’s the link to the forum post with all the details:
http://codeigniter.com/forums/viewthread/151827/
http://forum.codeigniter.com/thread-29403-post-182988.html#pid182988

If you just want the code, here’s the link:
http://solepixel.pastebin.com/6DHpxXuz

The reason I wrote these 2 items in was because:
1. I usually keep to a similar naming convention with models: m_modelname. The reason is because in an application, we’ve found that common entities will all typically have the same name. I.E. Model, View, and Controller. An example would be a Contact page. There’s controllers/contact.php, models/contact.php, views/contact.php. With all three files open at once, they all look like contact.php. Also when searching files, they all 3 show up which makes it hard to distinguish between all 3. I suppose one day it might be a good idea to keep to this naming convention with views as well, but not today đŸ™‚

2. Usually most sites we do have a CMS backend attached to it. The CMS usually has models for handling everything for each bit of data, like retrieve all, retrieve one, update, delete, etc. I often find I need access to some of these methods from the frontend application and end up creating a model on the frontend with the exact same methods. Well this causes problems when table structures change and both models need to get updated to reflect the new structure. This extension resolves that problem and allows you to load a model from another CI application. It even will load from a different site if it’s on the same server. An example of this is we have a live site (domain.com) and a mobile site (m.domain.com) and both sit on the same server. So now I can access models from the live site from within the mobile site!

Hope this helps someone out. I hear CI 2 is supposed to support this and it’s called packages and package_path. Phil Sturgeon writes about it here. Please comment if you like it or have any thoughts on how to improve/enhance it.

Write a Comment