Javatpoint Logo
Javatpoint Logo

CodeIgniter Methods

In the earlier Hello World example, our method name is index(). By default Controller always calls index method. If you want a different method, then write it in the Controller's file and specify its name while calling the function.

Codeigniter Methods 1

Look at the URL, there is no method name is mentioned. Hence, by default index method is loaded.


Method other than index()

Here, we have mentioned a method called newFunction(). Now we have to call this new method to run our program.

Create a controller page Hello.php in application/controllers.

Look at the above snapshot, we have created a function newFunction.

Create a view page hello_world.php in application/views.

To run this program on our browser, follow path

http://localhost/CodeIgniter/index.php/Hello/newFunction

Codeigniter Methods 4

Look at the above snapshot, we created the Controller's function as newFunction and specified it in the URL after Controller's name.

Here, /index.php/Hello is Controller's name.

And /newFunction is the Function name.


Remapping Method Calls

Second segment of URI determines which method is being called. If you want to override it you can use _remap() method.

If you have mentioned _remap() method in your controllers, it will always get called even if URI is different. It overrides the URI.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA