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

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

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加