Tutorialsplane

Codeigniter Remap Function


Codeigniter Remap Function : Codeigniter Remap Function is used to override the default function called in url.


For example : www.example.com/User/profile where Home is controller and user is method(function) name.

You can override the function name “profile” with other function name in the controller.
Means you can map original function name with your custom name in url.

Codeigniter Remap Function Example


For example if want to map url www.example.com/User/your_custom_name

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

class User extends CI_Controller {
public function _remap($method){
  switch ($method) {
     case 'about' : 
      $this-?>about_me();// call about_me() function.
     break;
     case 'edu' : 
      $this->education();// call education() function.
     break;
     default :
      $this->index();
     break;

}

}
public function index(){

echo "Welcome to index function."; 

}

public function profile(){
 echo "Welcome to profile function";
}
public function about_me(){
 echo "Hi I am John !";
}
public function education(){
 echo " I am Master in Computer application.";
}


}   
?>                         

1. Example :

Map http://localhost/User/about to the http://localhost/User/about_me

Hit the url

http://localhost/User/about

Where about calls about_me() function.

Demo

2. Example :

Map http://localhost/User/edu to the http://localhost/User/education

Hit the url

http://localhost/User/edu

Where edu calls education() function.

Demo

Models

Connect Database

Helpers

Libraries

Helper Reference

Library Reference

Database Reference