2

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

Community
  • 1
  • 1
  • What do you mean by _mandatory index function_? A controller is not required to have an index method. – AgRizzo Oct 03 '14 at 11:06
  • when i removed index function from class then i got such errors : Error: The action index is not defined in controller userController Error: Create userController::index() in file: app\Controller\userController.php. – Muhammad sohail Afzal Oct 03 '14 at 11:34
  • You need to perform some basic troubleshooting. The error is obviously caused by an http request which either directly or indirectly requests your UserController's index method. In other words, the index method is only "mandatory" because of your application - Cakephp does not require an index method per controller. – AgRizzo Oct 03 '14 at 11:45

2 Answers2

2

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.

Vivek Shukla
  • 207
  • 1
  • 9
0

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.

Daljeet Singh
  • 704
  • 3
  • 7
  • 17