CodeIgniter is a simple web application development framework for PHP . By its modular approach we can use its inbuilt libraries and helpers.

It has a three-tier architecture i.e. Model-View-Controller (MVC) which is easy to use by which the functional process logic, data access, data storage and user interface can be developed.

You can also refer our previous tutorial For CodeIgniter installation and configuration.

What is MVC..?

MVC stands for Model, View, Controller. It is a programing pattern used in developing Web applications. This pattern separates the user interface and backend.

Using  MVC, developers can implement or modify their interface or back-end without affecting the other files. MVC also increases the flexibility of an app by being able to reuse models or views over again.

codeigniter mvc model view controller

Below is a description of MVC.

Model:
The model deals with the raw data and database interaction and will contain functions
like inserting records to a database or selecting specific database records.

View:
The view deals with displaying the data and interface controls to the user with.

Controller:
The controller acts as mediator to interact with view and model. It act as a single point of control from where you can manage both model and view.

Now you will learn how to run a sample program. Before we start with a sample program we assume that you have already install CodeIgniter on your system if not than you have to download and install it first.

Steps to create CodeIgniter’s first sample program:-

Step:1
First, in controller, create a file name “ci_sample_controller.php” within path: C:\wamp\www\CodeIgniter\application\controllers. Write following code:

<?php
class ci_sample_controller extends CI_Controller {

public function __construct() {
parent::__construct();
}

//This is Default function of controller
public function index() {
//Loading view file ci_sample_view.php
$this->load->view('ci_sample_view');
}

public function Hello() {
//Loading view file ci_sample_view.php
$this->load->view('ci_sample_view');
}

}
?>

Step:2  Next step, in view. Create “ci_sample_view.php” within C:\wamp\www\CodeIgniter\application\views. Write just simple line code like:

<?php

echo "Hello World";

?>

To run a file:

http://localhost/codeigniter/index.php/ci_sample_controller/hello

You can also refer:codeigniter sample application

Note: By default controller calls the index function and if you want to call your defined function then you have to specify it while calling.

You can also download the Script file. Extract the downloaded files and run it on your Local server.

Conclusion:

Thanks for reading the complete post. Hope you have got the concept. You can share your views in the space provided below and get in touch with us.