boj
boj

Reputation: 11395

cakephp - redirecting unauthenticated user on "Missing method" error

CakePHP authentication/redirection to "users/login" works great if I'm not authenticated and I try to open the page ie. "/posts/view/2".

But if I try to get ie. "/users/somethingNotExisting" then CakePHP threw

Missing Method in UsersController

Error: The action somethingNotExisting is not defined in controller UsersController

Error: Create UsersController::somethingNotExisting() in file: app/Controller/UsersController.php.

It's bad:

How can I force CakePHP to redirect any unauthenticated unknown action to the login page?

Upvotes: 0

Views: 1994

Answers (1)

Alex Stallen
Alex Stallen

Reputation: 2252

the error message you are getting is only in development mode, if you set your debug level to 0 in app/Config/core.php Configure::write('debug', 0); you will get a normal 404 not found response wich you can customize to your liking in app/View/Errors/error400.ctp

if people see your menu when not logged in that is your own fault for not 'hiding' that part for not logged in users

The error page views are located at app/View/Errors/. For all 4xx and 5xx errors the view files error400.ctp and error500.ctp are used respectively. You can customize them as per your needs. By default your app/Layouts/default.ctp is used for error pages too. If for eg. you want to use another layout app/Layouts/my_error.ctp for your error pages, then simply edit the error views and add the statement $this->layout = 'my_error'; to the error400.ctp and error500.ctp. This way you can hide whatever default layout and/or navigation you want

Upvotes: 2

Related Questions