How can I get the action name in a Symfony2 controller?

后端 未结 5 1744
北恋
北恋 2020-12-17 22:40

Is there a way to get the name of the action in a Symfony2 controller?

public function createAction(Request $request, $title) {

    // Expected result: crea         


        
5条回答
  •  温柔的废话
    2020-12-17 23:24

    In all version of symfony and without $request or container, service or nothing else... , directly in your method

    public function myMethod(){
       $methodName = __METHOD__;
       return $methodName;
    }
    
    // return App\Controller\DefaultController::myMethod
    
    public function mySecondMethod(){
       $methodName = explode('::', __METHOD__);
       return $methodName[1];
    }
    
    // return mySecondMethod
    

提交回复
热议问题