[英]Implementing authentication in PHP F3 framework
What's the recommended way of doing the auth checks? 推荐进行身份验证的方法是什么? I really don't want to duplicate the auth checks all over the code in every single route, and while they have the before/after route hooks if you use objects, I would still like to minimize how often I'm repeating that code.
我真的不想在每条路径中的所有代码中重复进行auth检查,并且如果您使用对象的话,虽然它们具有之前/之后的路由钩子,但我仍想尽量减少重复代码的频率。
Is there a global 'before/after' route hook for everything and/or what's the recommended way of solving this problem? 是否存在针对所有事物的全局“前后”路由钩子和/或解决此问题的推荐方法是什么?
If you don't want to duplicate the auth checks in every single route, then you'd better create a base class extended by every single controller class: 如果您不想在每个路由中都复制auth检查,那么最好创建一个由每个控制器类扩展的基类:
abstract class secureController {
function beforeRoute($f3,$params) {
//...
if ($auth_failed)
$f3->error(401);//or 403
}
}
class controller1 extends secureController {
function route1() {}
function route2() {}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.