Codeigniter Configuration

In this tutorial you will learn about the Codeigniter Configuration and its application with practical example.

Configuring base URL

The base URL defines the root of our application. Open the config.php file located in application/config/config.php directory.

Find the following line of code –

Change it with the our project URL as shown below –

Removing index.php from URLs

Open the project URL http://localhost/codeigniter/welcome in your browser, you will get the following error –

remove-index_php

this is because codeigniter is a MVC framework and in codeigniter all requests go through index.php, this will work fine if you open above URL including index.php slug (http://localhost/codeigniter/index.php/welcome)

To fix the above problem, let’s open the config.php file located in application/config/config.php directory.

Find the following line of code –

Replace it with the following line of code –

Now, create a new file called .htaccess and place it inside your project root. Put the following lines of code in .htaccess file –

Now, visit the project URL http://localhost/codeigniter/welcome in your browser

Note:- You must have mod_rewrite enabled.

Database configuration

To setup database connection, open the database.php file located in application/config/database.php directory. Here you will find following lines of code, database configuration settings are stored in an array –

Change the default values for hostname, username, password, and database with your database details

Configuring default route/controller

In CodeIgniter framework, default controller is the controller that automatically called when one isn’t specified. Open the routes.php file located in application/config/routes.php directory.

Find the following line of code –

Currently, CodeIgniter have a default controller called “welcome.php” that is located in application/controllers directory. Change it with the controller name that you want to loaded as default one.

Autoload Configuration

Let’s open the autoload.php file located in application/config/autoload.php directory, this file is used to configure the libraries, helpers, languages and models that you want to be automatically loaded.

All of these configuration are stored as an array, you need to append libraries, helpers, languages and models name to the corresponding array that you want to be automatically loaded.

Example:-

In this tutorial we have learn about the Codeigniter Configuration and its application with practical example. I hope you will like this tutorial.