ThinkPHP5.*获取当前模块,控制器,方法

TP5中怎么获取当前模块当前控制器呢?

方法可能有很多种,这里只是提供一种

可以在控制器中通过中Request实例化类获取当前模型/控制器/方法

use think\Controller;
class Index extends Controller
{
public function test(Request $request)
  {
    $this->assign('controller',$request->controller());
    $this->assign('module',$request->module());
    $this->assign('action',$request->action());
  }
}
/*视图文件中
{$controller}
{$module}
{$action}
    

*/

猜你喜欢

转载自blog.csdn.net/benben0729/article/details/81302554