Codeigniter Controller Function And Parameters

Codeigniter controller function and parameters : The codeigniter controller contains the methods inside it. The parameters passed in url along with function name are directly received inside the methods.

Codeigniter controller function And parameters Example

Lets Understand with the following example and demo :

defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {
function index(){

echo "Welcome to index function."; 


function profile(){
 echo "Welcome to profile function";

function comments($id=null,$name=null){
   echo "Id: ". $id."<br>";
   echo "Name: ". $name."<br>";

1. Call index() function :

To access index() function hit like this :


Where index calls index() function.


Try it »

1. Call profile() function :

To access profile() function hit like this :


Where profile calls function() function.


Try it »

1. Call comments() function with parameters :

You can define default parameter in function as :

commnts($id = null, $name = null)

Access the comments function with parameter :


Where first parameter is id and second is name as defined in parameter which will be received in parameters $id, $name .


Try it »

Add Comment

📖 Read More