我的情况:我有一个由AJAX请求触发的NavigatorController,并且会
$这个 - >进( "controllername")
请求.但是如何根据控制器名称检查控制器是否存在?当然,在实际转发之前发生并在页面控制器不存在时抛出错误.
您实际上可以使用 Symfony 使用的 controller_resolver服务来检查控制器是否存在.
public function indexAction(Request $request)
{
$request->attributes->set('_controller', 'AppBundle\Controller\ExampleController::exampleAction');
try{
$this->get('debug.controller_resolver')->getController($request);
} catch (\Exception $e) {
$x = $e->getCode();
}
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!
| 归档时间: |
|
| 查看次数: |
684 次 |
| 最近记录: |