Javatpoint Logo
Javatpoint Logo


What is Controller

A controller is the intermediary between models and views to process HTTP request and generates a web page. All the requests received by the controller are passed on to models and views to process the information. It is the center of every request on your web application.

Consider following URI,

In this URI, CodeIgniter will try to find Front.php file and Front class.

Controller Syntax

controller 1

Look at the above snaphsot, controller's file name is Main.php (first letter has to be in uppercase) and class name is Main (first letter has to be in uppercase).

What is Default Controller

The file specified in default controller will be loaded by default when no file name is mentioned in the URL. By default, it is Welcome.php which is the first page to be seen after installing CodeIgniter.

With URL

Welcome.php will be loaded as there is no file name mentioned in the URL.

Although as per your need, you can change default controller in the file application/config/routes.php.

Here, specify your file name which you want to be loaded by default.

Class Constructors

To use a constructor you need to mention the following line of code,

We need to manually call the parent constructor because local constructor will be overriding the one in the parent controller.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA