YII - 我们如何在控制器的init()函数中获取方法的名称?
In a YII work, I have an init() function which checks whether the session is set if not redirect to login page.
The problem is that the "login" action is also in the same controller, so it is creating an infinite loop. If I can get the method name in init() function, I can solve this issue.
How I can get the method name in init() function?
在YII工作中,我有一个init()函数,它检查会话是否设置,如果没有重定向到登录 页面。 p>
问题是“登录”操作也在同一个控制器中,因此它创建了一个无限循环。 如果我可以在init()函数中获取方法名称,我可以解决这个问题。 p>
如何在init()函数中获取方法名? p> div>
Current Controller
Yii::app()->controller->id
and Current Action
Yii::app()->controller->action->id
To check action id in all functions other than init(), because init function initializes the controller...
So the solution for your problem will be let the request come to the actionLogin in your login controller..and there you check if session is not check redirect him from where he is coming..else perform the login action..That way you'll not face loop problem..