看看这个Symfony\Bundle\FrameworkBundle\Controller
类,使用该handle()
方法似乎是一种方法,因为他们已经弃用了框架包中的整个 httpkernal 类:
public function forward($controller, array $path = array(), array $query = array())
{
$path['_controller'] = $controller;
$subRequest = $this->container->get('request')->duplicate($query, null, $path);
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
有关弃用更改日志,请参见此处:
https://github.com/symfony/FrameworkBundle/blob/master/CHANGELOG.md#220
因此,您可以执行以下操作:
public function onKernelException(GetResponseForExceptionEvent $event)
{
$subRequest = $this->container->get('request')->duplicate(array(), null, array("_controller" => 'MyBundle:Default:page'));
$response = $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}