Go and get CodeIgniter
Before we begin I wil quickly mention the config file, found in /system/application/config/config.php. This file contains all sorts of settings but the only one you need to change is - $config['base_url'] = "http://127.0.0.1/CodeIgniter/"; on line 14. Change it to http://localhost/ci_tutorial/ or http://localhost:8888/ci_tutorial/ if using MAMP.
You don't actually install CI as such, you really just arrange it, copying the files onto your server and adjusting a few settings, installation is really too grand a term for this I think.
At the time of writing the latest CI version available is CodeIgniter 1.6.1 so go and get it and unzip it into your DOCUMENT_ROOT (remember from the last section? this folder will probably be called htdocs or www).
Rename the 'CodeIgniter_1.6.1 folder to 'ci_tutorial' for easier navigation (and you may have more than one CI installation eventually) and visit it in your browser (MAC: http://localhost:8888/ci_tutorial/ - PC: http://localhost/ci_tutorial/) and you should see the CI welcome page.
Congratulations
So that's all there is to it, Codeigniter is installed. There is however still a few settings we need to tweak to make everything work properly. Now we will discuss these settings and then I'll walk through the processes involved in CI producing the welcome screen you have just seen.
Index.php - the Boostrap
Ever heard the expression "Pull yourself up by your bootstraps" no? Well essentailly it means sort yourself out - take action to improve or change your current situation. Bootstrap files or programs are found all over the place, they help computers and programs sort themselves out when they are first activated. The index.php file in your ci_tutorial folder, is the CodeIgniter bootstrap. It is the first file to get things done. let's have a look at it.
Index.php is quite well commented so forgive me for repeating some of what is already written in the file, the first item we arive at in the index.php file is the error reporting:
Error Reporting
error_reporting(E_ALL) - this is a native php function, any php script or program can use this function to set the level of error reporting. This exists so that you can decide what to do when an error is encountered, either display it to the screen (good during development) or try to continue silently (best for production). It's current setting E_ALL means that all errors and notices will be reported, this should help with your debugging. Set it to 0 if you want to trun error reporting off.
[error_repoting()]In order to ensure that errors are actually printed to the screen you can add the php ini directive ini_set('display_errors', 'On') here.
$system_folder
The system folder contains al the CodeIgniter files so your index.php file needs to know where it is. You can leave this variable set to 'system' becuase we haven't altered the default layout.
$application_folder
Similarly to the system folder your index.php file needs to know where the application folder is (by default it is inside the system folder) you can leave this setting as it is.
Set server path
Codeigniter perfoms some php magic here to determine the full server path to your CodeIgniter installation. It then uses this path to generate paths to important files. You do not need to edit this section.
The strpos($system_folder, '/') function checks for the position of '/' in the $system_folder variable that you set earlier, it retuns a value of FALSE if '/' is not found.
[strpos()]String functions are some of the most useful, and commonly used fuctions in php, they can be used to search and edit strings in all sorts of ways, check the php manual for more string functions.
Define Application Constants
A constant in php is a varaible that does not change (so it's not variable at all) once set a constant is available all over your scripts, they can only store simple data, like a pth to file or a name, but they are ver useful when bootstrapping an application becuase they enable you to create stores of datya that you can later rely on.
CodeIgniter sets constants that hold the file extension you are using (.php), and a number of paths that will be helpfull later.
Constants are created using the php define() function like this: define('MY_CONSTANT', 'some simple data here');Constants are always all in upper-case.
[PHP constants]Load the front controller
At this stage the index.php file has done all it needs to spark (or perhaps ignite?) CodeIgniter into action, so it now includes the codeigniter core file with this statement:
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
require_once tells php to go and get another file, if it has not already been gotten and include in the current run of things, think of this as including one file in another. Notice that the BASEPATH constant is used to give require_once the full path to the codeigniter.php file.
In a later tutorial I will walk through the CodeIgniter.php file (and others), but I think that is is probably enough for now. The next section deal with editing and creating views.
- 1. Introduction
- 2. Setting up a development server
- 3. CodeIgniter walkthrough (index.php)
- 4. Editing and creating views
Get CodeIgniter
At the time of writing the latest CI version available is CodeIgniter 1.6.1 so go and get it and unzip it into your DOCUMENT_ROOT (remember from the last section? this folder will probably be called htdocs or www).
Pull yourself up by your bootstraps
The index.php file in your ci_tutorial folder, is the CodeIgniter bootstrap. It is the first file to get things done.
Constants
A constant in php is a varaible that does not change (so it's not variable at all) once set a constant is available all over your scripts, they can only store simple data, like a pth to file or a name
Front Controller
The front controller is the main codeigniter file that calls the application into action.