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

后端 未结 5 1748
北恋
北恋 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:31

    use:

    $request->attributes->get('_controller');
    // will get yourBundle\Controller\yourController::CreateAction
    
    $params = explode('::',$request->attributes->get('_controller'));
    // $params[1] = 'createAction';
    
    $actionName = substr($params[1],0,-6);
    // $actionName = 'create';
    

提交回复
热议问题