关于网友提出的“ thinkphp5怎么获取 CONTROLLER_NAME”问题疑问,本网通过在网上对“ thinkphp5怎么获取 CONTROLLER_NAME”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: thinkphp5怎么获取 CONTROLLER_NAME
描述:tp5没有CONTROLLER_NAME了,怎么获取CONTROLLER名称
解决方案1:$request = \think\Request::instance();
echo $request->controller();exit;
解决方案2:好像没有了,,那就自己获取呗。。。
使用__CLASS__试试,还有获取方法的, METHOD__, __FUNCTION 不过要截取。。。
解决方案3:public function test(Request $request)
{
dump($request->controller());
}
多看源码
/**
* 设置或者获取当前的模块名
* @access public
* @param string $module 模块名
* @return string|Request
*/
public function module($module = null)
{
if (!is_null($module)) {
$this->module = $module;
return $this;
} else {
return $this->module ?: '';
}
}
/**
* 设置或者获取当前的控制器名
* @access public
* @param string $controller 控制器名
* @return string|Request
*/
public function controller($controller = null)
{
if (!is_null($controller)) {
$this->controller = $controller;
return $this;
} else {
return $this->controller ?: '';
}
}
/**
* 设置或者获取当前的操作名
* @access public
* @param string $action 操作名
* @return string|Request
*/
public function action($action = null)
{
if (!is_null($action)) {
$this->action = $action;
return $this;
} else {
return $this->action ?: '';
}
}
以上介绍了“ thinkphp5怎么获取 CONTROLLER_NAME”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/4182453.html