Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

Tutorial make controller Codeigniter

Document Sample
Tutorial make controller Codeigniter Powered By Docstoc
					Tutorial Codeigniter 2

Controller

before you know what it is CodeIgniter, I'll explain what it was MVC. MVC or
ModelView Controller is a method for making an application by
separating data (Model)from the view (View) and how to process it (Controller)
in the user guide codeigniter (http://codeigniter.com/user_guide/overview/mvc.html)has expl
ained that


understand?
okay we are just implementations of the controller
Please create a file called hello.php in the controllers folder (example / application /
controllers)


 hello file extension is. php




<?php
Class <file name> extends CI_Controller {
        function __construct(){
                parent::__construct();
                         }
        function index(){
                //write code in here
                         }
}
?>
function index is a function of the first run when the controller is called
controller hello


<?php
class Hello extends CI_Controller {
         function __construct(){
                 parent::__construct();
                 //echo "hello world";
         }
         function index(){
                 echo "hello world";
         }

}
?>
after completion please visit http://localhost/example/index.php/hello in your favorite
browser




to the calling controller can be seen in the picture below




Add function getdata in hello controller.

function getdata($data){
                 echo "Data = ".$data;
        }
and visit here http://localhost/example/index.php/hello/getdata/3 (3) can be replaced with
another because of the function with paramerter




explanation




Other example

function plus($a,$b){
  $result = $a+$b;
  echo $result;
}
complete code

<?php

class Hello extends CI_Controller {
       function __construct(){
         parent::__construct();
         //echo "hello world";
       }
       function index(){
         echo "hello world";
       }
       function getdata($data){
         echo "Data = ".$data;
       }

        function plus($a,$b){
          $result = $a+$b;
          echo $result;
        }
}
?>

Change file routes.php in folder the config search $route['default_controller']="welcome"; to
$route['default_controller'] ="hello"; then you can immediately visiting localhost/example is
the controller hello


The next tutorial is to discuss the 'view'

				
DOCUMENT INFO
Shared By:
Stats:
views:86
posted:7/30/2011
language:English
pages:4
Description: discusses how to create a controller in CodeIgniter