In codeigniter we have the standard classes of an mvc framework, models,views, libraries,etc. I’d like to add my own sub-set of objects to CodeIgniter, how can I best go about that? for example:
directories:
controllers
core
helpers
etc..
widgets //custom object type
inside of core, I could have a My_Widget class that everything in the widget folder would extend. Then, inside of a controller I could have something like:
$this->load->widget('Example_Widget');
I have never done this so I can’t offer you a complete solution, but I can at least try to point you in the right direction.
Take a look at the Loader Class, located in
/system/core/Loader.php. This is what you are accessing when you use$this->load. It contains a number of methods for loading resources of different types (models, libraries, etc). You may be able to get away with duplicating themodel()method, renaming itwidget(), and updating the paths to check an/application/widgetsdirectory. You might need to do a little more, such as creating a CI_Widget base class, but you should be able to go line by line through the method and figure out what it requires to work.I hope this helps.
Edit (1/12/2012):
Here is an example of someone extending CodeIgniter to support a custom resource type.
Sparks is a package management system for CodeIgniter much like RubyGems for Ruby. Using a spark is simple. Once you have modified your CodeIgniter environment to support sparks, you simply install the spark and then load it using
$this->load->spark('...');. Modifying your CodeIgniter environment to support sparks simply entails extending the Loader Class to support the newsparks()method.The code for modifying the Loader Class is available here. Following the pattern in that file, you should be able implement loading of your own custom resource types. In my previous answer I said that you could get away with modifying the
/system/core/Loader.phpfile although I would recommend you follow the approach used by sparks and use a/application/core/MY_Loader.phpfile.