YII - 我们如何在控制器的 init() 函数中获取方法的名称? [英] YII - how we can get the name of the method in init() function in controller?

查看:54
本文介绍了YII - 我们如何在控制器的 init() 函数中获取方法的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 YII 的工作中,我有一个 init() 函数,它检查会话是否设置,如果没有重定向到登录页面.

In a YII work, I have an init() function which checks whether the session is set if not redirect to login page.

问题在于登录"操作也在同一个控制器中,因此它正在创建一个无限循环.如果我能在 init() 函数中得到方法名,我就可以解决这个问题.

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.

如何在 init() 函数中获取方法名称?

How I can get the method name in init() function?

推荐答案

Current Controller

Current Controller

Yii::app()->controller->id 

和当前操作

Yii::app()->controller->action->id

要检查除 init() 以外的所有函数中的 action id,因为 init 函数会初始化控制器...

To check action id in all functions other than init(), because init function initializes the controller...

因此,您的问题的解决方案是让请求到达您的登录控制器中的 actionLogin ..然后您检查会话是否未检查重定向他从他来的地方..否则执行登录操作..那这样你就不会遇到循环问题..

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..

这篇关于YII - 我们如何在控制器的 init() 函数中获取方法的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆