CodeIgniter Configuration

What is Configuration in CodeIgniter?

Configuration in CodeIgniter means setting up your application’s basic options so that it works correctly.

It includes defining things like base URL, database settings, session handling, encryption keys, etc.

👉 In CodeIgniter, configuration files are located in:

application/config/

Each file handles a specific part of your app. Example:

  • config.php → General app settings (base URL, index file, etc.)
  • database.php → Database connection settings
  • autoload.php → Libraries, helpers, packages to load automatically
  • routes.php → Application routing rules


Main Configuration Files in CodeIgniter

1. config.php (Main App Settings)

Here you set basic application options.

Example:

$config['base_url'] = 'http://localhost/ci-app/';
$config['index_page'] = 'index.php';
$config['encryption_key'] = 'myStrongSecretKey123!';
  • base_url → Your project’s main URL
  • index_page → Default entry page (can remove using .htaccess)
  • encryption_key → Important for sessions & security


2. database.php (Database Settings)

This file stores DB connection details.

Example:

$db['default'] = array(
  'hostname' => 'localhost',
  'username' => 'root',
  'password' => '',
  'database' => 'ci_tutorial',
  'dbdriver' => 'mysqli',
);


3. autoload.php (Auto Loading Components)

If you want some libraries/helpers/models to load automatically, configure them here.

Example:

$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url', 'form');
  • Saves you from loading them manually each time.


4. routes.php (Routing)

Defines how URLs are mapped to controllers.

Example:

$route['default_controller'] = 'welcome';
$route['about'] = 'pages/about';
$route['contact'] = 'pages/contact';


5. constants.php (App Constants)

Used to define global constants like file paths, versions, etc.

Example:

define('SITE_NAME', 'My CodeIgniter Tutorial Site');
define('UPLOAD_PATH', 'uploads/');


Best Practices in Configuration

  • Always set a base_url for proper link generation.
  • Use a strong encryption key in config.php.
  • Never store DB passwords in public repos.
  • Use autoload only for frequently used libraries (too many slows down app).
  • Keep separate configs for development & production.

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.