CakePHP获取操作名称 [英] CakePHP get action name

查看:116
本文介绍了CakePHP获取操作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CakePHP中,可以使用

In CakePHP, it is possible to get the called function string using the

$this->action

语法。它返回任何被调用的字符串,所以如果URL / do_this ,它返回 do_this doThis 它会返回 doThis 。不管被调用方法的真实名称。

syntax. It returns the literal string of whatever is called, so if the URL is /do_this, it returns do_this, and if it's doThis it'll return doThis. Regardless of the called method's real name.

另一方面,我正在寻找的是被调用方法的实际名称,不管URL语法。

What I am looking for, on the other hand, is the called method's actual name, no matter the URL syntax.

有办法找到吗?

我最好能够在 beforeFilter 方法。

推荐答案

您应该使用请求对象。

$this->request->params['action'];

我认为这应该包含被调用的实际方法名称。 CakePHP路由器将字符串URL解析为控制器/操作对和其他参数,所有这些都在请求对象中结束。阅读文档并在beforeFilter()中执行 debug($ this-> request); ,看看还有什么。

I think this should contain the real method name that was called. CakePHPs router resolves the string URL to a controller / action pair and other args, all of that ends up in the request object. Read the documentation and do debug($this->request); in your beforeFilter() to see what else is there.

这篇关于CakePHP获取操作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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