1

这是怎么回事?

我应该用什么来代替 $this->forward()?

PHP 已弃用:forward() 自 2.2 版以来已弃用,并将在 2.3 中删除。在 /app/bootstrap.php.cache 上线...

--

我正在运行它:

public function onKernelException(GetResponseForExceptionEvent $event)
{

   $httpKernel = $this->container->get('http_kernel');
   $response = $httpKernel->forward('MyBundle:Default:pageAction');

   //etc.
4

1 回答 1

0

看看这个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);
}
于 2013-04-15T10:49:43.483 回答