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

时间:2013-04-15 10:22:05

标签: symfony

这是怎么回事?

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

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

-

我正在运行它:

public function onKernelException(GetResponseForExceptionEvent $event)
{

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

   //etc.

1 个答案:

答案 0 :(得分: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);
}