PHP 框架 - 单向路由
在 CodeIgniter 的路由文件中,可以将 URL 映射到控制器方法,如下所示:
$route['url/segment/(:num)'] = 'controller/methodasdf/$1';
它工作得很好,但我想做的是阻止用户直接调用最终路由 (methodasdf
)。我尝试将方法设置为 private
并用下划线作为前缀,但这只会导致 404 错误。
In CodeIgniter's routes file, it is possible to map URLs to controller methods like this:
$route['url/segment/(:num)'] = 'controller/methodasdf/$1';
It works great, but what I'd like to do is stop the user calling the end route directly (methodasdf
). I've tried setting the methods to private
and prefixing them with an underscore, but that just results in a 404 error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在控制器中,您可以检查 $this->uri->segment(1) == 'your_nice_segment' 是否存在,如果不是,您可以向他显示错误
In the controller you can check if $this->uri->segment(1) == 'your_nice_segment' and if it's not you can show him an error