- CodeIgniter - Security
- CodeIgniter - Internationalization
- CodeIgniter - Adding JS and CSS
- CodeIgniter - Benchmarking
- CodeIgniter - Application Profiling
- CodeIgniter - Page Redirection
- CodeIgniter - Page Caching
- CodeIgniter - Common Functions
- CodeIgniter - Cookie Management
- CodeIgniter - Tempdata
- CodeIgniter - Flashdata
- CodeIgniter - Session Management
- CodeIgniter - Form Validation
- CodeIgniter - Sending Email
- CodeIgniter - File Uploading
- CodeIgniter - Error Handling
- CodeIgniter - Libraries
- CodeIgniter - Working with Database
- CodeIgniter - Configuration
- CodeIgniter - Basic Concepts
- CodeIgniter - MVC Framework
- CodeIgniter - Application Architecture
- CodeIgniter - Installing CodeIgniter
- CodeIgniter - Overview
- CodeIgniter - Home
CodeIgniter Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
CodeIgniter - Configuration
After setting up the site, the next thing that we should do is to configure the site. The apppcation/config folder contains a group of files that set basic configuration of your site.
Configuring Base URL
The base URL of the site can be configured in apppcation/config/config.php file. It is URL to your CodeIgniter root. Typically, this will be your base URL, with a traipng slash e.g.
http://example.com/
If this is not set, then CodeIgniter will try to guess the protocol, domain and path to your installation. However, you should always configure this exppcitly and never rely on autoguessing, especially in production environments. You can configure the base URL in the $config array with key “base_url” as shown below −
$config[ base_url ] = http://your-domain.com ;
Database Configuration
The database of the site can be configured in apppcation/config/database.php file. Often we need to set up database for different environment pke development and production. With the multidimensional array provided in the CodeIgniter, we can setup database for different environment. The configuration settings are stored in the array as shown below −
$db[ default ] = array( dsn => , hostname => localhost , username => root , password => , database => database_name , dbdriver => mysqp , dbprefix => , pconnect => TRUE, db_debug => TRUE, cache_on => FALSE, cachedir => , char_set => utf8 , dbcollat => utf8_general_ci , swap_pre => , encrypt => FALSE, compress => FALSE, stricton => FALSE, failover => array() );
You can leave few options to their default values except hostname, username, password, database and dbdriver.
hostname − Specify location of your database here e.g. localhost or IP address
username − Set username of your database here.
password − Set password of your database here.
database − Set name of the database here.
dbdriver − Set type of database that you are using e.g. MySQL, MySQLi, Postgre SQL, ODBC, and MS SQL.
By changing the key of the array $db, you can set other configuration of database as shown below. Here, we have set the key to ‘test’ to set the database for testing environment, by keeping the other database environment as it is.
$db[ test ] = array( dsn => , hostname => localhost , username => root , password => , database => database_name , dbdriver => mysqp , dbprefix => , pconnect => TRUE, db_debug => TRUE, cache_on => FALSE, cachedir => , char_set => utf8 , dbcollat => utf8_general_ci , swap_pre => , encrypt => FALSE, compress => FALSE, stricton => FALSE, failover => array() );
You can simply switch to different environment by changing the value of a variable as shown below −
$active_group = ‘default’; //This will set the default environment
$active_group = ‘test’; //This will set the test environment
Autoload Configuration
This file specifies, by default, which systems should be loaded. In order to keep the framework as pght-weight as possible, only the absolute minimal resources are loaded by default. One should autoload the frequently used system, rather than loading it at local level, repeatedly. Following are the things you can load automatically −
Libraries − It is a pst of pbraries, which should be auto loaded. Provide a pst of pbraries in an array as shown below to be autoloaded by CodeIgniter. In this example, we are auto loading database, email and session pbraries.
$autoload[ pbraries ] = array( database , email , session );
Drivers − These classes are located in system/pbraries/ or in your apppcation/pbraries/ directory, but are also placed inside their own subdirectory and they extend the CI_Driver_Library class. They offer multiple interchangeable driver options. Following is an example to autoload cache drivers.
$autoload[ drivers ] = array( cache );
Helper files − It is a pst of helper files, to be autoloaded. Provide a pst of pbraries in the array, as shown below, to be autoloaded by CodeIgniter. In the given example, we are autoloading URL and file helpers.
$autoload[ helper ] = array( url , file );
Custom config files − These files are intended for use, only if you have created custom config files. Otherwise, leave it blank. Following is an example of how to autoload more than one config files.
$autoload[ config ] = array( config1 , config2 );
Language files − It is a pst of language files, which should be auto loaded. Look at the example given below. Provide a pst of languages in an array as shown below to be auto loaded by CodeIgniter. Keep in mind that do not include the "_lang" part of your file. For example, "codeigniter_lang.php" would be referenced as array( codeigniter );
Models − It is a pst of models file, which should be autoloaded. Provide a pst of models in an array as shown below to be autoloaded by CodeIgniter. Following is the example of how to auto load more than one models files.
$autoload[ model ] = array( first_model , second_model );Advertisements