Skip to content

Fixed route examples #11085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed route examples
  • Loading branch information
Jules Pietri committed Mar 4, 2019
commit d245b451b2ba323350d61f5a719a76d340b6f78f
7 changes: 3 additions & 4 deletions components/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ routes with UTF-8 characters:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="route1" path="/category/{name}">
<default key="_controller">App\Controller\DefaultController::category</default>
<route id="route1" path="/category/{name}" controller="App\Controller\DefaultController::category">
<option key="utf8">true</option>
</route>
</routes>
Expand Down Expand Up @@ -498,8 +497,8 @@ You can also include UTF-8 strings as routing requirements:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="route2" path="/default/{default}">
<default key="_controller">App\Controller\DefaultController::default</default>
<route id="route2" path="/default/{default}"
controller="App\Controller\DefaultController::default">
<requirement key="default">한국어</requirement>
<option key="utf8">true</option>
</route>
Expand Down
11 changes: 5 additions & 6 deletions controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ a service like: ``App\Controller\HelloController::index``:
class HelloController
{
/**
* @Route("/hello", name="hello")
* @Route("/hello", name="hello", methods={"GET"})
*/
public function index()
{
Expand All @@ -45,7 +45,8 @@ a service like: ``App\Controller\HelloController::index``:
# config/routes.yaml
hello:
path: /hello
defaults: { _controller: App\Controller\HelloController::index }
controller: App\Controller\HelloController::index
methods: GET

.. code-block:: xml

Expand All @@ -56,9 +57,7 @@ a service like: ``App\Controller\HelloController::index``:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="hello" path="/hello">
<default key="_controller">App\Controller\HelloController::index</default>
</route>
<route id="hello" path="/hello" controller="App\Controller\HelloController::index" methods="GET" />

</routes>

Expand All @@ -67,7 +66,7 @@ a service like: ``App\Controller\HelloController::index``:
// config/routes.php
$collection->add('hello', new Route('/hello', [
'_controller' => 'App\Controller\HelloController::index',
]));
], [], [], '', [], ['GET']));

.. _controller-service-invoke:

Expand Down
12 changes: 5 additions & 7 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ Now you can configure the routes:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog_list" controller="App\Controller\BlogController::list" path="/blog" >
<route id="blog_list" path="/blog" controller="App\Controller\BlogController::list">
<!-- settings -->
</route>

<route id="blog_show" controller="App\Controller\BlogController::show" path="/blog/{slug}">
<route id="blog_show" path="/blog/{slug}" controller="App\Controller\BlogController::show">
<!-- settings -->
</route>
</routes>

.. code-block:: php

// config/routes.php
use App\Controller\BlogController;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use App\Controller\BlogController;

$routes = new RouteCollection();
$routes->add('blog_list', new Route('/blog', [
Expand Down Expand Up @@ -407,8 +407,7 @@ concise, but it can decrease route readability when requirements are complex:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog_list" path="/blog/{page<\d+>}"
controller="App\Controller\BlogController::list" />
<route id="blog_list" path="/blog/{page<\d+>}" controller="App\Controller\BlogController::list" />

<!-- ... -->
</routes>
Expand Down Expand Up @@ -572,8 +571,7 @@ placeholder:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog_list" path="/blog/{page <\d+>?1}"
controller="App\Controller\BlogController::list" />
<route id="blog_list" path="/blog/{page <\d+>?1}" controller="App\Controller\BlogController::list" />

<!-- ... -->
</routes>
Expand Down
5 changes: 3 additions & 2 deletions routing/conditions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ define arbitrary matching logic, use the ``conditions`` routing option:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="contact" path="/contact">
<default key="_controller">App\Controller\DefaultController::contact</default>
<route id="contact"
path="/contact"
controller="App\Controller\DefaultController::contact">
<condition>context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'</condition>
<!-- expressions can also include config parameters -->
<!-- <condition>request.headers.get('User-Agent') matches '%app.allowed_browsers%'</condition> -->
Expand Down
5 changes: 3 additions & 2 deletions routing/extra_information.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ to your controller, and as attributes of the ``Request`` object:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog" path="/blog/{page}">
<default key="_controller">App\Controller\BlogController::index</default>
<route id="blog"
path="/blog/{page}"
controller="App\Controller\BlogController::index">
<default key="page">1</default>
<default key="title">Hello world!</default>
</route>
Expand Down
58 changes: 28 additions & 30 deletions routing/hostname_pattern.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ You can also match on the HTTP *host* of the incoming request.
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="mobile_homepage" path="/" host="m.example.com">
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
</route>
<route id="mobile_homepage"
path="/"
host="m.example.com"
controller="App\Controller\MainController::mobileHomepage" />

<route id="homepage" path="/">
<default key="_controller">App\Controller\MainController::homepage</default>
</route>
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
</routes>

.. code-block:: php
Expand Down Expand Up @@ -104,9 +103,9 @@ you can use placeholders in your hostname:
class MainController extends AbstractController
{
/**
* @Route("/", name="projects_homepage", host="{project_name}.example.com")
* @Route("/", name="projects_homepage", host="{project}.example.com")
*/
public function projectsHomepage()
public function projectsHomepage(string $project)
{
// ...
}
Expand All @@ -125,7 +124,7 @@ you can use placeholders in your hostname:
# config/routes.yaml
projects_homepage:
path: /
host: "{project_name}.example.com"
host: "{project}.example.com"
controller: App\Controller\MainController::projectsHomepage

homepage:
Expand All @@ -141,13 +140,12 @@ you can use placeholders in your hostname:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="projects_homepage" path="/" host="{project_name}.example.com">
<default key="_controller">App\Controller\MainController::projectsHomepage</default>
</route>
<route id="projects_homepage"
path="/"
host="{project}.example.com"
controller="App\Controller\MainController::projectsHomepage" />

<route id="homepage" path="/">
<default key="_controller">App\Controller\MainController::homepage</default>
</route>
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
</routes>

.. code-block:: php
Expand All @@ -159,7 +157,7 @@ you can use placeholders in your hostname:
$routes = new RouteCollection();
$routes->add('project_homepage', new Route('/', [
'_controller' => 'App\Controller\MainController::projectsHomepage',
], [], [], '{project_name}.example.com'));
], [], [], '{project}.example.com'));

$routes->add('homepage', new Route('/', [
'_controller' => 'App\Controller\MainController::homepage',
Expand Down Expand Up @@ -231,15 +229,15 @@ instance, if you want to match both ``m.example.com`` and
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="mobile_homepage" path="/" host="{subdomain}.example.com">
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
<route id="mobile_homepage"
path="/"
host="{subdomain}.example.com"
controller="App\Controller\MainController::mobileHomepage">
<default key="subdomain">m</default>
<requirement key="subdomain">m|mobile</requirement>
</route>

<route id="homepage" path="/">
<default key="_controller">App\Controller\MainController::homepage</default>
</route>
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
</routes>

.. code-block:: php
Expand Down Expand Up @@ -327,15 +325,15 @@ instance, if you want to match both ``m.example.com`` and
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="mobile_homepage" path="/" host="m.{domain}">
<default key="_controller">App\Controller\MainController::mobileHomepage</default>
<route id="mobile_homepage"
path="/"
host="m.{domain}"
controller="App\Controller\MainController::mobileHomepage">
<default key="domain">%domain%</default>
<requirement key="domain">%domain%</requirement>
</route>

<route id="homepage" path="/">
<default key="_controller">App\Controller\MainController::homepage</default>
</route>
<route id="homepage" path="/" controller="App\Controller\MainController::homepage" />
</routes>

.. code-block:: php
Expand Down Expand Up @@ -376,7 +374,7 @@ You can also set the host option on imported routes:
.. code-block:: php-annotations

// src/Controller/MainController.php
namespace App\Controller;
namespace Acme\HelloBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -393,7 +391,7 @@ You can also set the host option on imported routes:

# config/routes.yaml
app_hello:
resource: '@ThirdPartyBundle/Resources/config/routing.yaml'
resource: '@AcmeHelloBundle/Resources/config/routing.yaml'
host: "hello.example.com"

.. code-block:: xml
Expand All @@ -405,13 +403,13 @@ You can also set the host option on imported routes:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<import resource="@ThirdPartyBundle/Resources/config/routing.xml" host="hello.example.com" />
<import resource="@AcmeHelloBundle/Resources/config/routing.xml" host="hello.example.com" />
</routes>

.. code-block:: php

// config/routes.php
$routes = $loader->import("@ThirdPartyBundle/Resources/config/routing.php");
$routes = $loader->import("@AcmeHelloBundle/Resources/config/routing.php");
$routes->setHost('hello.example.com');

return $routes;
Expand Down
11 changes: 3 additions & 8 deletions routing/optional_placeholders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ the available blog posts for this imaginary blog application:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog" path="/blog">
<default key="_controller">App\Controller\BlogController::index</default>
</route>
<route id="blog" path="/blog" controller="App\Controller\BlogController::index" />
</routes>

.. code-block:: php
Expand Down Expand Up @@ -98,9 +96,7 @@ entries? Update the route to have a new ``{page}`` placeholder:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog" path="/blog/{page}">
<default key="_controller">App\Controller\BlogController::index</default>
</route>
<route id="blog" path="/blog/{page}" controller="App\Controller\BlogController::index" />
</routes>

.. code-block:: php
Expand Down Expand Up @@ -159,8 +155,7 @@ This is done by including it in the ``defaults`` collection:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="blog" path="/blog/{page}">
<default key="_controller">App\Controller\BlogController::index</default>
<route id="blog" path="/blog/{page}" controller="App\Controller\BlogController::index">
<default key="page">1</default>
</route>
</routes>
Expand Down
27 changes: 14 additions & 13 deletions routing/redirect_in_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ action to redirect to this new url:

# load some routes - one should ultimately have the path "/app"
controllers:
resource: ../src/Controller/
resource: '../src/Controller/'
type: annotation
prefix: /app

Expand All @@ -50,14 +50,12 @@ action to redirect to this new url:
http://symfony.com/schema/routing/routing-1.0.xsd">

<!-- load some routes - one should ultimately have the path "/app" -->
<import resource="../src/Controller/"
type="annotation"
prefix="/app"
/>
<import resource="../src/Controller/" type="annotation" prefix="/app" />

<!-- redirecting the homepage -->
<route id="homepage" path="/">
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
<route id="homepage"
path="/"
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
<default key="path">/app</default>
<default key="permanent">true</default>
</route>
Expand Down Expand Up @@ -129,8 +127,9 @@ action:

<!-- ... -->

<route id="admin" path="/wp-admin">
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction</default>
<route id="admin"
path="/wp-admin"
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction">
<default key="route">sonata_admin_dashboard</default>
<!-- make a permanent redirection... -->
<default key="permanent">true</default>
Expand Down Expand Up @@ -218,17 +217,19 @@ permanent redirects use ``308`` code instead of ``301``:
http://symfony.com/schema/routing/routing-1.0.xsd">

<!-- redirects with the 308 status code -->
<route id="route_foo" path="...">
<route id="route_foo"
path="..."
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
<!-- ... -->
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
<default key="permanent">true</default>
<default key="keepRequestMethod">true</default>
</route>

<!-- redirects with the 307 status code -->
<route id="route_bar" path="...">
<route id="route_bar"
path="..."
controller="Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction">
<!-- ... -->
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction</default>
<default key="permanent">false</default>
<default key="keepRequestMethod">true</default>
</route>
Expand Down
Loading