Thursday, June 23, 2016

Codeigniter tutorial

   No comments     
categories: 

CodeIgniter  

                        Is light Weight
                        No installation required
                        Flexible

CodeIgniter has a very efficient URL structure, it generates a well optimised Search engine friendly URL.

URL Routing in CodeIgniter

General URL structure for CodeIgniter:
<baseURL>/index.php/<controller_name>/<controller_function>

Download CodeIgniter here.

I renamed the extracted CodeIgniter folder into 'code' for my convenience. My PHP development environment is XAMPP. So, 'code' folder location will be 
C:\xampp\htdocs

type 'localhost/code' on a browser, it shows the CodeIgniter welcome message. if not check your XAMPP Control Panel.

First, I create a controller function. 


hello.php

<?php
class Hello extends CI_Controller{
public function first(){
echo "This is the first method";
}
}
?>

Here the file name is 'hello.php', where the class name is capitalised file name, that is 'Hello' and the base class is CI_Controller.

for call the method in the browser, type localhost/code/index.php/hello/first

hello is the controller name and the first is the controller function name.
The output is:


Function with Parameters

We can input parameters inside the parenthesis. the same program,

<?php
class Hello extends CI_Controller{
public function first($p1,$p2){
echo "This is the first method <br>";
echo "My parameters are : $p1 and $p2";
}
}
?>

Here I have created two parameters as $p1 and $p2
So the URL for calling the function with parameters is 
localhost/code/index.php/hello/first/one/two

and the output was:



  thus, you can change the value for the parameter and get the output as your wish.

0 comments:

Post a Comment