CodeIgniter - Configuration

CodeIgniter - Configuration
After setting up the site, the next thing we need to do is set up the site. The application/config folder contains a group of files that define the basic configuration of your site.
Setting the Base URL
The site's base URL can be configured in the application/config/config.php file. This is the URL of your CodeIgniter root. Typically, this will be your base url with a slash, e.g.
http://example.com/
If this is not set, CodeIgniter will try to guess the protocol, domain, and path of your installation. However, you should always set this up explicitly and never rely on autodetection, especially in production environments. You can configure base url in $config array with key "base_url" as shown below −
$config['base_url'] = 'http://your-domain.com';
Database configuration
The site database can be configured in the application/config/database.php file. Often we need to set up a database for different environments such as development and production. With the multidimensional array provided in CodeIgniter, we can set up a database for a different environment. The configuration settings are stored in an array as shown below −
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'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 a few options to their defaults, except for hostname, username, password, database, and dbdriver.
- hostname - enter the location of your database here, e.g. localhost or IP address
- username - Enter your database username here.
- password - Set your database password here.
- database - enter the name of the database here.
- dbdriver - sets the type of database you are using, such as MySQL, MySQLi, Postgre SQL, ODBC and MS SQL.
hostname - enter the location of your database here, e.g. localhost or IP address
username - Enter your database username here.
password - Set your database password here.
database - enter the name of the database here.
dbdriver - sets the type of database you are using, such as MySQL, MySQLi, Postgre SQL, ODBC and MS SQL.
By changing the $ db array key , you can set a different database configuration as shown below. Here we set the 'test' key to set the database for the test environment while keeping the other database environment as it is.
$db['test'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'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 another environment by changing the variable value as shown below −
$active_group='default'; // This will set the default environment
$active_group='test'; // This will set up the test environment
Autoload Configuration
This file specifies which systems should be booted by default. To make the wireframe as light as possible, only the absolute minimum resources are loaded by default. You should boot a frequently used system rather than booting it locally. Following are the things that you can download automatically −
- Libraries is a list of libraries that should be loaded automatically. Provide a list of libraries in an array as shown below for CodeIgniter to automatically load. In this example, we are automatically loading databases, email, and session libraries.
Libraries is a list of libraries that should be loaded automatically. Provide a list of libraries in an array as shown below for CodeIgniter to automatically load. In this example, we are automatically loading databases, email, and session libraries.
$autoload['libraries'] = array('database', 'email', 'session');
- Drivers. These classes are in the system/library/ directory or your application/library/ directory, but are also inside their own subdirectory and extend the CI_Driver_Library class. They offer several interchangeable driver options. Below is an example of autoloading cache drivers.
Drivers. These classes are in the system/library/ directory or your application/library/ directory, but are also inside their own subdirectory and extend the CI_Driver_Library class. They offer several interchangeable driver options. Below is an example of autoloading cache drivers.
$autoload['drivers'] = array('cache');
- Support Files is a list of support files that should be loaded automatically. Provide a list of libraries in an array as shown below for automatic loading with CodeIgniter. In this example, we are automatically loading URLs and file helpers.
Support Files is a list of support files that should be loaded automatically. Provide a list of libraries in an array as shown below for automatic loading with CodeIgniter. In this example, we are automatically loading URLs and file helpers.
$autoload['helper'] = array('url', 'file');
- User settings files. These files are intended to be used only if you have created custom settings files. Otherwise, leave this field blank. Below is an example of how to automatically load more than one configuration file.
User settings files. These files are intended to be used only if you have created custom settings files. Otherwise, leave this field blank. Below is an example of how to automatically load more than one configuration file.
$autoload['config'] = array('config1', 'config2');
- Language files is a list of language files that should be loaded automatically. Look at the example below. Provide a list of languages ​​in an array as shown below for CodeIgniter to load automatically. Be aware that don't include the _lang part in your file. For example, "codeigniter_lang.php" would be specified as an array ("codeigniter");
Language files is a list of language files that should be loaded automatically. Look at the example below. Provide a list of languages ​​in an array as shown below for CodeIgniter to load automatically. Be aware that don't include the _lang part in your file. For example, "codeigniter_lang.php" would be specified as an array ("codeigniter");
- Models is a model list file that should be loaded automatically. Provide a list of models in an array like below for automatic loading with CodeIgniter. Below is an example of automatic loading of multiple model files.
Models is a model list file that should be loaded automatically. Provide a list of models in an array like below for automatic loading with CodeIgniter. Below is an example of automatic loading of multiple model files.
$autoload['model'] = array('first_model', 'second_model');