Преглед изворни кода

added ControllerResolver::forward() (will probably move it elsewhere later on)

Fabien Potencier пре 15 година
родитељ
комит
38edd2aafa

+ 1 - 5
src/Symfony/Bundle/FrameworkBundle/Controller.php

@@ -5,7 +5,6 @@ namespace Symfony\Bundle\FrameworkBundle;
 use Symfony\Components\DependencyInjection\ContainerInterface;
 use Symfony\Components\HttpFoundation\Request;
 use Symfony\Components\HttpFoundation\Response;
-use Symfony\Components\HttpKernel\HttpKernelInterface;
 
 /*
  * This file is part of the Symfony framework.
@@ -93,10 +92,7 @@ class Controller
      */
     public function forward($controller, array $path = array(), array $query = array())
     {
-        $path['_controller'] = $controller;
-        $subRequest = $this->getRequest()->duplicate($query, null, $path);
-
-        return $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
+        return $this->container->get('controller_resolver')->forward($controller, $path, $query);
     }
 
     /**

+ 17 - 0
src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

@@ -69,6 +69,23 @@ class ControllerResolver extends BaseControllerResolver
         return array(new $class($this->container), $method);
     }
 
+    /**
+     * Forwards the request to another controller.
+     *
+     * @param  string  $controller The controller name (a string like BlogBundle:Post:index)
+     * @param  array   $path       An array of path parameters
+     * @param  array   $query      An array of query parameters
+     *
+     * @return Response A Response instance
+     */
+    public function forward($controller, array $path = array(), array $query = array())
+    {
+        $path['_controller'] = $controller;
+        $subRequest = $this->getRequest()->duplicate($query, null, $path);
+
+        return $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
+    }
+
     /**
      * Renders a Controller and returns the Response content.
      *