CodeIgniter provides a
CI_Controller that is meant to be used as the basis for all of your own controllers. It handles the behind-the-scenes work of assigning class vars and the Loader so that you can access them. Bonfire extends this concept and provides 4 additional Controllers that can be used as base classes throughout your project. This helps you to keep from repeating code any more than necessary by providing a central place for any site-wide code to sit. For example, it makes a user object available that can be accessed from any controller, library, or view to know details about the current user. You can use it to set a custom theme for all of your public pages. And much more.
Each controller is stored in its own file in the
application/libraries folder and the file is named the same as the class name. This allows the provided autoloader to easily find your base classes.
MY_Controller file is currently not used by Bonfire and is left alone so that you can use it for your own needs.
Each controller type is meant to serve a specific purpose, but they are all easily adaptable to fit your needs. This files are meant to be customized for your application! Don't be afraid to edit them. That said, however, please be sure to back the files up during any upgrades of Bonfire.
All of the custom controllers extend from the
Base_Controller. This class extends the MX_Controller which gives you all of the power of WireDesign’s HMVC available to all of your classes. That allows for a different way of working, but also a very powerful one, and one that is not necessary to use.
This controller is the place that you want to setup anything that should happen for every page of your site, like:
Some of the things that would normally be auto-loaded are handled here so that any AJAX controllers you may write don't need to process any of these other settings.
By default, Bonfire's Base_Controller provides the following features for any of your classes that extend it:
$requested_pageclass vars that help you know where you came from. These are auto-populated for you.
$current_userclass var that, if logged in, will contain all of the information from the users table, as well as a link to the user's avatar. This same information is automatically made available to the view files that are rendered with the Template class.
activity modelloaded and ready.
Front_Controller is intended to be used as the base for any public-facing controllers. As such, anything that needs to be done for the front-end can be done here.
Currently, it simply ensures that the Assets and Template libraries are available. You could also set the active and default themes here, if you create a parent theme ‘framework’ to use with all of your sites that you extend with child themes.
This controller forms the base for the Admin Controller. It was broken into two parts in case you needed to create a front-end area that was only accessible to your users, but that was not part of the Admin area and didn’t share the same themes, etc. All changes you make here will affect your Admin Controller’s, though, so use with care. If you need to, reset the values in the Admin Controller.
This controller currently...
The final controller sets things up even more for use within the Admin area of your site. That is, the area that Bonfire has setup for you as a base of operations. It currently...
Creating controllers in Bonfire is nearly identical to creating controllers in straight CodeIgniter. The only difference is the naming of some of the classes when you're dealing with the Administration side of Bonfire and Contexts.