浏览代码

[FrameworkBundle] Adding the redirect method back to the base controller

Some question whether or not the base Controller should be included at all. I think it absolutely must be included because it's important for beginners and for rapid development of smaller features/applications (and rapid development is good for beginners).

So, assuming that we *do* like the base Controller, we should really use it to its fullest potential - making the lives of developers as easy as possible.
Ryan Weaver 14 年之前
父节点
当前提交
9ee9f5552b
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

+ 14 - 0
src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

@@ -12,6 +12,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Controller;
 
 use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\DependencyInjection\ContainerAware;
 
 /**
@@ -51,6 +52,19 @@ class Controller extends ContainerAware
         return $this->container->get('http_kernel')->forward($controller, $path, $query);
     }
 
+    /**
+     * Returns a RedirectResponse to the given URL.
+     *
+     * @param string  $url The URL to redirect to
+     * @param integer $status The status code to use for the Response
+     *
+     * @return RedirectResponse
+     */
+    public function redirect($url, $status = 302)
+    {
+        return new RedirectResponse($url, $status);
+    }
+
     /**
      * Returns a rendered view.
      *