-
Notifications
You must be signed in to change notification settings - Fork 1
Bonfire Controllers
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 many 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 type is meant to server a specific purpose, but they are all easily adaptable to fit your needs. This file is meant to be customized for your application! Don't be afraid to edit it. That said, however, please be sure to back the file 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:
- Setup environment-specific settings, like turning the profiler on for development and off for production and testing.
- Get the cache setup correctly. This is currently setup to only use a file-based cache, but you can easily tell it to use APC if available, and fallback to the file system if not.
- This controller also sets up System Events that will get executed just before and just after the Base_Controller’s constructor runs.
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.
The 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 sets the active theme. You could also set the default theme 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...
- Loads in all of the user-associated models, like the user_model, permission_model, etc
- Restricts access to only logged in users
- Gets form_validation setup and working correctly with HMVC.
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...
- Sets the pagination settings for a consistent user experience.
- Gets the admin theme loaded and makes sure that some consistent CSS files are loaded so we don’t have to worry about it later.
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.
Getting Started With Bonfire
Installing Bonfire
Change Log
Bonfire Models
Bonfire Migrations
Bonfire Controllers
Contexts
Layouts and Views
Working With Assets
Changing Admin URL
Global Helpers
Keyboard Shortcuts
Module Builder
System Events
Performance Tips
How to Contribute
API Documentation Guidelines
Bonfire Guides Guidelines
Bonfire Bug Report Guide