2019-01-10 14:13:40 来源:未知 作者:IT零五 278
Thinkphp5.1版本相对5.0版本升级了很多地方。
比如我们在Thinkphp5.0中通过以下方法可以获取当前访问的模块名、控制器名、方法名:
use think\Request;
/*
代码段
*/
$module = Request::instance()->module();
$controller = Request::instance()->controller();
$action = Request::instance()->controller();
而在5.1版本中Request类没有instance方法,我们可以通过Facade特性直接静态化调用,具体如下:
use think\facade\Request;
/*
代码段
*/
$module = Request::module();
$controller = Request::controller();
$action = Request::controller();
在模板中直接可以这样
{define name="CONTROLLER_NAME" value=":\think\facade\Request::controller()" /}
{define name="ACTION_NAME" value=":\think\facade\Request::action()" /}
{define name="MODULE_NAME" value=":\think\facade\Request::module()" /}
最佳答案