Forráskód Böngészése

Merge remote branch 'weaverryan/controller_not_found_exception'

* weaverryan/controller_not_found_exception:
  [FrameworkBundle] Adding a shortcut method to the controller for throwing the NotFoundHttpException
Fabien Potencier 14 éve
szülő
commit
9162e4c760

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

@@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\DependencyInjection\ContainerAware;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
 /**
  * Controller is a simple implementation of a Controller.
@@ -92,6 +93,20 @@ class Controller extends ContainerAware
         return $this->container->get('templating')->renderResponse($view, $parameters, $response);
     }
 
+    /**
+     * Returns a NotFoundHttpException.
+     *
+     * This will result in a 404 response code. Usage example:
+     *
+     *     throw $this->createNotFoundException('Page not found!');
+     *
+     * @return NotFoundHttpException
+     */
+    public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
+    {
+        return new NotFoundHttpException($message, $previous);
+    }
+
     /**
      * Returns true if the service id is defined.
      *