diff --git a/controller/argument_value_resolver.rst b/controller/argument_value_resolver.rst index 8ca6af7179d..811d226bc64 100644 --- a/controller/argument_value_resolver.rst +++ b/controller/argument_value_resolver.rst @@ -42,11 +42,6 @@ Symfony ships with five value resolvers in the HttpKernel component: argument list. When the action is called, the last (variadic) argument will contain all the values of this array. -.. note:: - - Prior to Symfony 3.1, this logic was resolved within the ``ControllerResolver``. - The old functionality is rewritten to the aforementioned value resolvers. - Adding a Custom Value Resolver ------------------------------ @@ -62,7 +57,7 @@ controller:: class UserController { - public function indexAction(User $user) + public function index(User $user) { return new Response('Hello '.$user->getUsername().'!'); } diff --git a/controller/csrf_token_validation.rst b/controller/csrf_token_validation.rst index 8775362a63d..e9db3189a56 100644 --- a/controller/csrf_token_validation.rst +++ b/controller/csrf_token_validation.rst @@ -9,7 +9,7 @@ want to use the Symfony Form component. If, for example, you are implementing a DELETE action, you can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::isCsrfTokenValid` method to check the validity of a CSRF token:: - public function deleteAction() + public function delete() { if ($this->isCsrfTokenValid('token_id', $submittedToken)) { // ... do something, like deleting an object diff --git a/controller/error_pages.rst b/controller/error_pages.rst index f247c168d01..c8bcc65b6b2 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -67,33 +67,32 @@ logic to determine the template filename: To override these templates, simply rely on the standard Symfony method for :doc:`overriding templates that live inside a bundle `: -put them in the ``app/Resources/TwigBundle/views/Exception/`` directory. +put them in the ``templates/bundles/TwigBundle/Exception/`` directory. A typical project that returns HTML and JSON pages, might look like this: .. code-block:: text - app/ - └─ Resources/ + templates/ + └─ bundles/ └─ TwigBundle/ - └─ views/ - └─ Exception/ - ├─ error404.html.twig - ├─ error403.html.twig - ├─ error.html.twig # All other HTML errors (including 500) - ├─ error404.json.twig - ├─ error403.json.twig - └─ error.json.twig # All other JSON errors (including 500) + └─ Exception/ + ├─ error404.html.twig + ├─ error403.html.twig + ├─ error.html.twig # All other HTML errors (including 500) + ├─ error404.json.twig + ├─ error403.json.twig + └─ error.json.twig # All other JSON errors (including 500) Example 404 Error Template -------------------------- To override the 404 error template for HTML pages, create a new -``error404.html.twig`` template located at ``app/Resources/TwigBundle/views/Exception/``: +``error404.html.twig`` template located at ``templates/bundles/TwigBundle/Exception/``: .. code-block:: html+twig - {# app/Resources/TwigBundle/views/Exception/error404.html.twig #} + {# templates/bundles/TwigBundle/Exception/error404.html.twig #} {% extends 'base.html.twig' %} {% block body %} @@ -139,21 +138,22 @@ what it looks like and debug it? Fortunately, the default ``ExceptionController`` allows you to preview your *error* pages during development. -To use this feature, you need to have a definition in your -``routing_dev.yml`` file like so: +To use this feature, you need to load some special routes provided by TwigBundle +(if the application uses :doc:`Symfony Flex ` they are loaded +automatically when installing Twig support): .. configuration-block:: .. code-block:: yaml - # app/config/routing_dev.yml + # config/routes/dev/twig.yaml _errors: - resource: "@TwigBundle/Resources/config/routing/errors.xml" + resource: '@TwigBundle/Resources/config/routing/errors.xml' prefix: /_error .. code-block:: xml - + + - AppBundle:Exception:showException + App\Controller\ExceptionController::showException .. code-block:: php - // app/config/config.php + // config/packages/twig.php $container->loadFromExtension('twig', array( - 'exception_controller' => 'AppBundle:Exception:showException', + 'exception_controller' => 'App\Controller\ExceptionController::showException', // ... )); diff --git a/controller/forwarding.rst b/controller/forwarding.rst index df8a4c685b1..47ec70e9425 100644 --- a/controller/forwarding.rst +++ b/controller/forwarding.rst @@ -11,9 +11,9 @@ sub-request and calls the defined controller. The ``forward()`` method returns the :class:`Symfony\\Component\\HttpFoundation\\Response` object that is returned from *that* controller:: - public function indexAction($name) + public function index($name) { - $response = $this->forward('AppBundle:Something:fancy', array( + $response = $this->forward('App\Controller\OtherController::fancy', array( 'name' => $name, 'color' => 'green', )); @@ -26,10 +26,10 @@ from *that* controller:: The array passed to the method becomes the arguments for the resulting controller. The target controller method might look something like this:: - public function fancyAction($name, $color) + public function fancy($name, $color) { // ... create and return a Response object } Just like when creating a controller for a route, the order of the arguments -of ``fancyAction()`` doesn't matter: the matching is done by name. +of the ``fancy()`` method doesn't matter: the matching is done by name. diff --git a/controller/service.rst b/controller/service.rst index cc2c6450a73..6fffddd1711 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -15,12 +15,12 @@ Referencing your Service from Routing Registering your controller as a service is great, but you also need to make sure that your routing references the service properly, so that Symfony knows to use it. -If the service id is the fully-qualified class name (FQCN) of your controller, you're -done! You can use the normal ``AppBundle:Hello:index`` syntax in your routing and -it will find your service. +If the service id is the fully-qualified class name (FQCN) of your controller, +you're done! You can use the normal ``App\Controller\HelloController::index`` +syntax in your routing and it will find your service. -But, if your service has a different id, you can use a special ``SERVICEID:METHOD`` -syntax: +But, if your service has a different id, you can use a special +``service_id:method_name`` syntax: .. configuration-block:: @@ -31,8 +31,6 @@ syntax: // You need to use Sensio's annotation to specify a service id use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; // ... - - use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; /** * @Route(service="app.hello_controller") @@ -73,8 +71,8 @@ syntax: .. note:: - You cannot drop the ``Action`` part of the method name when using the - single colon notation. + When using the ``service_id:method_name`` syntax, the method name must + end with the ``Action`` suffix. .. _controller-service-invoke: @@ -114,7 +112,7 @@ service and use it directly:: $this->twig = $twig; } - public function indexAction($name) + public function index($name) { $content = $this->twig->render( 'hello/index.html.twig', diff --git a/controller/soap_web_service.rst b/controller/soap_web_service.rst index d3375bcd37e..d1b9ec72c5b 100644 --- a/controller/soap_web_service.rst +++ b/controller/soap_web_service.rst @@ -54,7 +54,7 @@ the :ref:`default services configuration setObject($helloService); @@ -96,8 +96,8 @@ into the content of the Response and clear the output buffer. Finally, you're ready to return the ``Response``. Below is an example calling the service using a `NuSOAP`_ client. This example -assumes that the ``indexAction()`` in the controller above is accessible via the -route ``/soap``:: +assumes that the ``index()`` method in the controller above is accessible via +the route ``/soap``:: $client = new \Soapclient('http://example.com/index.php/soap?wsdl'); diff --git a/controller/upload_file.rst b/controller/upload_file.rst index 8fde4da9b56..dc207c31e03 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -108,7 +108,7 @@ to :doc:`customize form rendering `): Finally, you need to update the code of the controller that handles the form:: // src/Controller/ProductController.php - namespace App\ProductController; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; @@ -121,7 +121,7 @@ Finally, you need to update the code of the controller that handles the form:: /** * @Route("/product/new", name="app_product_new") */ - public function newAction(Request $request) + public function new(Request $request) { $product = new Product(); $form = $this->createForm(ProductType::class, $product); @@ -161,7 +161,7 @@ controller to specify the directory in which the brochures should be stored: .. code-block:: yaml - # app/config/config.yml + # config/services.yaml # ... parameters: @@ -294,7 +294,7 @@ Now you're ready to use this service in the controller:: use App\Service\FileUploader; // ... - public function newAction(Request $request, FileUploader $fileUploader) + public function new(Request $request, FileUploader $fileUploader) { // ... @@ -393,14 +393,16 @@ Now, register this class as a Doctrine listener: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - + + + + - - - - + + + + + .. code-block:: php