duandaodao6951 2013-07-09 11:42
浏览 29
已采纳

cakephp - 在“Missing method”错误上重定向未经身份验证的用户

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:

  • I do not want to see error message

  • Creating missing_action.ctp is not okay, in this case everybody can see the default layout (with menu etc.)

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

  • 写回答

1条回答 默认 最新

  • dongzhiyi2006 2013-07-09 11:53
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致