CodeIgniter is a powerful PHP framework with a minimal footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.1
Table of contents
- CodeIgniter Home Page
- CodeIgniter Community
- CodeIgniter Application Architecture
- An Introduction to Views & Templating in CodeIgniter
In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.2
Application Flow Chart3
- The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
- The Router examines the HTTP request to determine what should be done with it.
- If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
- Security. Before the application controller is loaded, the HTTP request and any user submitted data are filtered for security.
- The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
- The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
Controllers are the heart of your application, as they determine how HTTP requests should be handled.4
A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc.5
Models are optionally available for those who want to use a more traditional MVC approach.6
Hooks - Extending the Framework Core7
CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files. When CodeIgniter runs it follows a specific execution process, diagramed in the Application Flow page. There may be instances, however, where you’d like to cause some action to take place at a particular stage in the execution process. For example, you might want to run a script right before your controllers get loaded, or right after, or you might want to trigger one of your own scripts in some other location.8
The following is a list of available hook points.
- pre_system Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.
- pre_controller Called immediately prior to any of your controllers being called. All base classes, routing, and security checks have been done.
- post_controller_constructor Called immediately after your controller is instantiated, but prior to any method calls happening.
- post_controller Called immediately after your controller is fully executed.
- display_override Overrides the _display() method, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to reference the CI superobject with $this->CI =& get_instance() and then the finalized data will be available by calling $this->CI->output->get_output().
- cache_override Enables you to call your own method instead of the _display_cache() method in the Output Library. This permits you to use your own cache display mechanism.
- post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.