Introducing CodeIgniter Framework in PHP

In this article you will see how to use the MVC architecture in PHP through the CodeIgniter framework.


Introduction

In the previous article I discussed MVC in PHP. In this article you will see how use MVC in PHP through the CodeIgniter framework. CodeIgniter is an Application Development Framework - a toolkit. Using CodeIgniter you can develop projects much faster than with the core PHP. The CodeIgniter framework is fully based on the MVC architecture. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task. You can download the CodeIgniter framework from: "http://codeigniter.com/".

How to Install CodeIgniter

First of all extract the zip file of CodeIgniter. After extracting the CodeIgniter file you will paste in the following position "c:\wamp\www\"  (paste) or c:\xampp\htdocs\ (paste).

Set URL in CodeIgniter

For setting the URL in CodeIgniter go to the local disk C->wamp->www->CodeIgniter->open CodeIgniter->open application folder->open config folder->open config.php file->write the following URL:

$config['base_url']='http://localhost/CodeIgniter/';

Creating the First Application in the CodeIgniter Framework

<?php
class Hello extends CI_Controller
{
  
public function index()
   {
    
echo "Hello Vineet !!";
   }
}
?>

This file is to be saved in c:\wamp\www\CodeIgniter\application\controllers\hello.php. Here CI_Controller is the predefined class which is stored in the c:\wamp\www\CodeIgniter\system\core\controller.php.

Output

Open the web browser and write the following URL:

"http://localhost/CodeIgniter/index.php/hello/"

1st.jpg

Create Second Application in CodeIgniter Framework

If you want to make your own function in CodeIgniter then you can do that like this:

<?php
class Hello extends CI_Controller
{
  
public function index()
   {
    
echo "Hello Vineet !!";
   }
  
function test()
   {
    
echo "Vineet Kumar Saini is MCA Qualified!!";
   }
}
?>

This file is to be saved in c:\wamp\www\CodeIgniter\application\controllers\hello.php.

Output

Open the web browser and write the following URL:

"http://localhost/CodeIgniter/index.php/hello/test/"

2nd.jpg

Create Application Using Views

<?php
class Hello extends CI_Controller
{
  
public function index()
   {
    
echo "Hello Vineet !!";
   }
  
function test()
   {
      $this->load->view (
'you'); //you is the views file
   }
}
?>

This file is to be saved in c:\wamp\www\CodeIgniter\application\controllers\hello.php.

Now we will create a view file like this:

<?php
echo "Vineet Kumar Saini is a Software Developer!!";
?>

This file is to be saved in c:\wamp\www\CodeIgniter\application\views\you.php.

Output

Open the web browser and write the following URL:

"http://localhost/CodeIgniter/index.php/hello/test/"

3rd.jpg

Conclusion

So in this article you saw how to create an application in the CodeIgniter framework in PHP. Using this article one can easily understand creation of the application in the CodeIgniter framework in PHP. 

Some Helpful Resources