有没有办法在 Symfony2 控制器中获取动作的名称?
Is there a way to get the name of the action in a Symfony2 controller?
public function createAction(Request $request, $title) {
// Expected result: create
$name = $this->getActionName();
}
使用:
$request->attributes->get('_controller');
// will get yourBundleControlleryourController::CreateAction
$params = explode('::',$request->attributes->get('_controller'));
// $params[1] = 'createAction';
$actionName = substr($params[1],0,-6);
// $actionName = 'create';
这篇关于如何在 Symfony2 控制器中获取操作名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!