Sunday 10 July 2011

Start using CodeIgniter




Obviously, the first step that you should take before using Code Igniter is installing its source files into your test web server. To do so, simply point your browser to the following url: http://codeigniter.com/downloads/. Download the ZIP file that contains these files.
Once you've accomplished this, unzip the package and upload its folders and files to a chosen directory of your web server. In my personal case, I saved it to a “/codeigniter/” directory under the server’s root, but you may want to select a different location.
Finally, navigate to the application/config/config.php file, then open it with your code editor and configure the following array settings, as shown below:

|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------

$config['base_url'] = "http://127.0.0.1/codeigniter/";


|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------

$config['index_page'] = "index.php";


|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------

$config['language'] = "english";


|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------

$config['charset'] = "UTF-8";


|--------------------------------------------------------------------------
| Cache Directory Path
|--------------------------------------------------------------------------

$config['cache_path'] = 'http://127.0.0.1/codeigniter/cache/';


|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;


|--------------------------------------------------------------------------
| Global XSS Filtering
|--------------------------------------------------------------------------

$config['global_xss_filtering'] = FALSE;


|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------

$config['compress_output'] = TRUE;


|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
|--------------------------------------------------------------------------

$config['rewrite_short_tags'] = FALSE;

As you can see, the above settings provide Code Igniter with crucial information about your web applications, including the base url of your site, the default language and character set, and the index file that will be utilized. Also, it’s possible to specify whether any output generated by an application should be filtered to prevent XSS attacks, and whether it should be cached and compressed previously.
Finally, there’s a number of simple options that tell Code Igniter how to handle session data. They are actually fairly easy to configure. Although, you should pay special attention to the following entries:

$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';

If a value of “TRUE” is assigned to the first array element, then Code Igniter will store all of your session data in a MySQL database table, whose name will be specified in the second entry. In this case, a FALSE value has been assigned to the first setting, meaning that session data will be saved to a temporary directory in the web server.
Lastly, it’s possible to configure whether the use of short PHP tags will be enabled within view files. This is something that will be discussed in more detail when I develop some sample applications for you. For now, I’ll keep this option disabled.
So far, so good. I showed how to configure the main entries of Code Igniter’s config.php file. Of course, when you edit the file in question, you’ll see that it contains a few additional settings. However, to keep things rather simple, I’m going to use only the ones discussed above.
Now that the “config.php” file has been properly setup, it’s time to move on and learn how to configure an additional file, which is located at /config/database.php and is used by Code Igniter when working with MySQL databases.

No comments:

Post a Comment