Muhammad sohail Afzal
Muhammad sohail Afzal

Reputation: 319

why in Cake PhP Controller index function needed?

why there is mandatory index function in cake php and how we can make an other function in a class, because i made a class in a controller and and also made a function which is index function but when i want to changes that function name there is an error? Kindly tell me if any one knows about it?Why we need to make index function and how to define that and how to make a new function in same class? I have also search but could find any satisfactory answer. Here are some links http://book.cakephp.org/ CakePHP check if user is logged in inside a view

Upvotes: 2

Views: 1051

Answers (2)

Daljeet Singh
Daljeet Singh

Reputation: 714

It is not mandatory to have index function in the controller, but if no action exist then by default cake search for index function, because by default index is searched by browser.

Upvotes: 0

Vivek Shukla
Vivek Shukla

Reputation: 207

Its not mandatory to have an index() function in the controller and cake will never ever generate error for this. Index function is only made, so that anyone hitting your controller without any action never sees the error related to framework.

Its a good practice to have index() function in classed and index.html or index.php file to avoid directory access.

Upvotes: 2

Related Questions