Short Courses: CodeIgniter (PHP MVC Framework)

CodeIgniter Framework

CodeIgniter Framework

Take your websites to the next level with CodeIgniter MVC Framework in just 1 week. This course is totally practical and provides hands-on experience to the participants. The following are the contents of this course:

  • Advanced PHP concepts
  • Object Oriented PHP
  • Understanding the MVC Architecture
  • Server communication using AJAX

Students are expected to bring their own Laptops/Notebooks.

The fee for this course is PKR 2,800 and all the fee collected will be donated to Mishkat Welfare Trust
From: 30th June to 4th July 2014
Timings: 1:30 PM to 4:00 PM
Venue: Olives School, Judicial Colony, Rawalpindi.

Limited transport facility available for female students. Please mention it in the Comments field and provide your address.

At least 5 students must be enrolled for the course to commence.


CodeIgniter Autocomplete for Komodo Edit

Komodo Edit is a great cross-platform, free IDE and editor. However native autocomplete doesn’t work when working with CodeIgniter. Adding the path to the CodeIgniter folder also doesn’t seem to solve the problem.

While searching over the internet, I got some clues of how to achieve it. All you have to do is create a file and name it autocomplete.php (you can name it whatever you like) and copy/paste the following into it:

 * @property CI_DB_active_record $db
 * @property CI_DB_forge $dbforge
 * @property CI_Benchmark $benchmark
 * @property CI_Calendar $calendar
 * @property CI_Cart $cart
 * @property CI_Config $config
 * @property CI_Controller $controller
 * @property CI_Email $email
 * @property CI_Encrypt $encrypt
 * @property CI_Exceptions $exceptions
 * @property CI_Form_validation $form_validation
 * @property CI_Ftp $ftp
 * @property CI_Hooks $hooks
 * @property CI_Image_lib $image_lib
 * @property CI_Input $input
 * @property CI_Language $language
 * @property CI_Loader $load
 * @property CI_Log $log
 * @property CI_Model $model
 * @property CI_Output $output
 * @property CI_Pagination $pagination
 * @property CI_Parser $parser
 * @property CI_Profiler $profiler
 * @property CI_Router $router
 * @property CI_Session $session
 * @property CI_Sha1 $sha1
 * @property CI_Table $table
 * @property CI_Trackback $trackback
 * @property CI_Typography $typography
 * @property CI_Unit_test $unit_test
 * @property CI_Upload $upload
 * @property CI_URI $uri
 * @property CI_User_agent $user_agent
 * @property CI_Validation $validation
 * @property CI_Xmlrpc $xmlrpc
 * @property CI_Xmlrpcs $xmlrpcs
 * @property CI_Zip $zip
 * Add addtional libraries you wish
 * to use in your controllers here
class CI_Controller {};

 * @property CI_DB_active_record $db
 * @property CI_DB_forge $dbforge
 * @property CI_Config $config
 * @property CI_Loader $load
 * @property CI_Session $session
 * Add addtional libraries you wish
 * to use in your models here.
class CI_Model {};

Save the file and now open Komodo Edit. From the menu, open Edit and select Preferences option. A dialog window will appear. From the Category on the left side, select Languages and then further select PHP option (as shown in the picture below):

CodeIgniter Autocomplete for Komodo Edit

CodeIgniter Autocomplete for Komodo Edit

Add the directory which contains the newly created autocomplete.php file to the section PHP Directories and restart Komodo.

This should be enough for the autocomplete!

Browser Back Button and Data Caching

By default, the web browser will always cache the data and when a user clicks on the browser Back button, the previously cached data will be loaded instead of generating a fresh request. While this is acceptable in most of the cases, some applications may not want this functionality. For example, a one-time form that has already been submitted etc.

All that is required is a set of instructions for the web browser. I have presented here three ways and any approach will be enough.


<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="Pragma" content="no-cache" />


header("Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");


$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache"); 

This will prevent your browser from caching the page.

Enabling Clean URLs for CodeIgniter

CodeIgniter by default will have to first load the index.php page which would then further load the rest of the pages. This can be removed from the URL simply by following these steps:

  1. Create a new file in the CodeIgniter root folder named .htaccess with the following contents.
    <IfModule mod_rewrite.c="">
        RewriteEngine On
        RewriteBase /
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Submitted by: Fabdrol
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
    <IfModule !mod_rewrite.c="">
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
        ErrorDocument 404 /index.php

    If CodeIgniter is not the webroot and is a subfolder then alter the line RewriteBase / to RewriteBase /[Sub Folder Name]/ where [Sub Folder Name] should be replaced by the actual name of the folder.

    Note: In case the above file doesn’t work, remove the <IfModule> opening and closing tags to test if for some reason Apache wasn’t able to load the module.

    Save the file.

  2. Open the file inside the CodeIgniter folder in the path application/config/config.php and alter the following line
    $config['index_page'] = 'index.php';

    Remove the ‘index.php’ to (empty string) and save.

  3. Enable the mod_rewrite module of Apache using the following command on Ubuntu:
    sudo a2enmod rewrite

    The Apache needs to be restarted before changes can take affect.

  4. Make sure the required settings are made in the sites file. In Ubuntu this file can be found at /etc/apache/sites-available/default and make the following changes:
           Options FollowSymLinks
           AllowOverride FileInfo
  5. Restart Apache using the following command:
    sudo service apache2 restart

Now test the website by using the URL without the index.php word and it should work fine.