Codeigniter MVC Framework PHP

First sample program – CodeIgniter

Step 1 :
In controller, create a file name “sampleController.php” on below path path:

C:\xampp\htdocs\CodeIgniter\application\controller.

Write following code:

<?php

class sampleController extends CI_Controller {

 

public function __construct() {

parent::__construct();

}

 

//This is Default function of controller

public function index() {

//Loading view file sampleView.php

$this->load->view(‘sampleView’);

}

 

public function Hello() {

//Loading view file sampleView.php

$this->load->view(‘sampleView’);

}

}

?>

Step 2 : In view folder. Create “sampleView.php” in below path

C:\xampp\htdocs\CodeIgniter\application\views

Write the following code:

<?php

 

echo “This is my first codeigniter program”;

 

?>

For run this file:

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

 

Note: By default controller calls the index function, if you want to call a specific function then you have to specify it while calling.

Leave a Reply

Your email address will not be published. Required fields are marked *