CodeIgniter
Load DB class from within a helper
# instantiate CI code
$CI =& get_instance();
$CI->load->database();
$results=$CI->db->query("SHOW FIELDS FROM $table LIKE '$field'");
...
Standard controller
Set up the standard file that will be call every time www.yoursite.com is access. Got to the file /system/application/config/routes.php and set $route['default_controller']='index';
Session library
- User data
- When unsetting an userdata[] value this value will be stored in a cookie and it doesn't go away, so be very carefull using it.
- Flash data
- For status alerts and quick messages use flashdata(). It will be automatically deleted after first use.
Download CodeIgniter (CI)
Contents |
Why use this framework?
The search for the perfect PHP framework can be a pain. Can’t explain why but most frameworks (Joomla, Drupal, Wordpress) don’t satisfy my need to have exactly what I want working the way I want, and not adapting my way of doing things to the constraints of someone else’s code. No! My code is my work and I want an organised way of doing things but I want freedom to do whatever I want as well. I’ve seen many frameworks being born and soon vanishing in the midst of patches and classes being published every day. One, thought, survived: CodeIgniter. It was the best thing I’ve seen on the world of web programs since WikiMedia.
CodeIgniter is well organised and allow a lot of flexibility necessary when freelance developers are hire, each one of them with a different type of code and style. Knowing the basic of CodeIgniter is necessary and as time consuming as any other framework; however the learning curve is pretty smooth because you use them at the same time you are coding. You don’t need most of it until after 1 or 2 days of full-time development and usual slow start on other frameworks, CodeIgniter allows you to do your code the way you want and as you improve it (when necessary) you can change and adapt part of the code that is already there and make it more ‘CodeIgniter-friendly’ and therefore more accessible to other parts of the program and faster to make further corrections and upgrades.
Code Structure
/codeigniter /applications /controllers /homepage.php //--> visible on the URL /views
URL Structure
www.yourdomain.com/homepage
- This page is a class that extends the object ‘Controller’
- It has to have the construct method
function __construct()
{
parent::Controller();
}
Namespaces
- Each method in this class can be called by adding the method name after the file name in the URL (www.yourdomain.com/homepage/show_messages)
- show_messages is the function inside the class Homepage (extends Controller) that is inside the file homepage.php.
class Homepage extends Controller
{
function show_messages()
{
Echo ‘Hello World!’;
}
}
- If you don’t specify the method, automatically the code will try to find one called index(). This is considered the standard method to call and
class Homepage extends Controller
{
function index()
{
Echo ‘Auto ran method!’;
}
function show_messages()
{
Echo ‘Hello World!’;
}
}