简体   繁体   English

Symfony:登录后,所有其他页面重定向

[英]Symfony: after login and all other pages redirect

after login, i want the user redirect to a page like polling, so he/she can't do or go to other menu if he/she doesn't done that polling. 登录后,我希望用户重定向到类似轮询的页面,因此,如果他/她未执行该轮询,则他/她将无法执行或进入其他菜单。
That polling is come from database which depends on the time range. 该轮询来自数据库,具体取决于时间范围。
If i put every controller to check if user has done polling or not and redirect to a page, doesn't it not efficient? 如果我让每个控制器检查用户是否已完成轮询并重定向到页面,这不是很有效吗?
And if i put it after login controller, user can click menu or point to other routing to pass that polling. 如果我将其放在登录控制器之后,则用户可以单击菜单或指向其他路由以通过该轮询。

The simpler solution would be to redirect the user to a specific action after the successfull login. 更简单的解决方案是在成功登录后将用户重定向到特定操作。 This actions will return the user to the main page or the polling page depending on whatever condition you prefer to set. 此操作将使用户返回到主页或轮询页面,具体取决于您希望设置的条件。 So this this action can be treated as an entry point of the user in the system. 因此,可以将此操作视为系统中用户的入口点。 Next, Using kernel.controller event dispatcher, check this action for every request. 接下来,使用kernel.controller事件分配器,为每个请求检查此操作。

You need to implement kernel.controller listener to check some condition on every request. 您需要实现kernel.controller侦听器,以检查每个请求的某些条件。 It will be the right way. 这将是正确的方法。 You will only need to define it in one place. 您只需要在一个地方定义它。

You can read about this approach at official docs: http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html 您可以在官方文档中了解有关此方法的信息: http : //symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM