Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfeaf032

Browse files
committed
[FrameworkBundle][Routing] Added new template and redirect routes configuration
1 parent753c797 commitfeaf032

File tree

9 files changed

+177
-124
lines changed

9 files changed

+177
-124
lines changed

‎controller/error_pages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ automatically when installing ``symfony/framework-bundle``):
165165
..code-block::php
166166
167167
// config/routes/dev/framework.php
168-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
168+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
169169
170170
return function (RoutingConfigurator $routes) {
171171
$routes->import('@FrameworkBundle/Resources/config/routing/errors.xml')

‎controller/service.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ a service like: ``App\Controller\HelloController::index``:
6464
6565
// config/routes.php
6666
use App\Controller\HelloController;
67-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
67+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
6868
6969
return function (RoutingConfigurator $routes) {
7070
$routes->add('hello', '/hello')

‎routing.rst

Lines changed: 131 additions & 72 deletions
Large diffs are not rendered by default.

‎routing/custom_route_loader.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Symfony provides several route loaders for the most common needs:
6464
..code-block::php
6565
6666
// config/routes.php
67-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
67+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
6868
6969
return function (RoutingConfigurator $routes) {
7070
// loads routes from the given routing file stored in some bundle
@@ -146,7 +146,7 @@ Take these lines from the ``routes.yaml``:
146146
..code-block::php
147147
148148
// config/routes.php
149-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
149+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
150150
151151
return function (RoutingConfigurator $routes) {
152152
$routes->import('../src/Controller', 'annotation');
@@ -200,7 +200,7 @@ and configure the service and method to call:
200200
..code-block::php
201201
202202
// config/routes.php
203-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
203+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
204204
205205
return function (RoutingConfigurator $routes) {
206206
$routes->import('admin_route_loader::loadRoutes', 'service');
@@ -378,7 +378,7 @@ What remains to do is adding a few lines to the routing configuration:
378378
..code-block::php
379379
380380
// config/routes.php
381-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
381+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
382382
383383
return function (RoutingConfigurator $routes) {
384384
$routes->import('.', 'extra');

‎security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ Next, you'll need to create a route for this URL (but not a controller):
861861
..code-block::php
862862
863863
// config/routes.php
864-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
864+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
865865
866866
return function (RoutingConfigurator $routes) {
867867
$routes->add('logout', '/logout')

‎security/form_login.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ configuration (``login``):
131131
132132
// config/routes.php
133133
use App\Controller\SecurityController;
134-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
134+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
135135
136136
return function (RoutingConfigurator $routes) {
137137
$routes->add('login', '/login')

‎security/json_login_setup.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ The next step is to configure a route in your app matching this path:
111111
112112
// config/routes.php
113113
use App\Controller\SecurityController;
114-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
114+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
115115
116116
return function (RoutingConfigurator $routes) {
117117
$routes->add('login', '/login')

‎templates.rst

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Consider the following routing configuration:
245245
246246
// config/routes.php
247247
use App\Controller\BlogController;
248-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
248+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
249249
250250
return function (RoutingConfigurator $routes) {
251251
$routes->add('blog_index', '/')
@@ -457,8 +457,8 @@ Rendering a Template Directly from a Route
457457
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
458458

459459
Although templates are usually rendered in controllers and services, you can
460-
render static pagesthat don't need any variables directly fromtheroute
461-
definition. Use the special:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\TemplateController`
460+
render static pagesfrom the route definition. Usethespecial
461+
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\TemplateController`
462462
provided by Symfony:
463463

464464
..configuration-block::
@@ -468,19 +468,17 @@ provided by Symfony:
468468
# config/routes.yaml
469469
acme_privacy:
470470
path:/privacy
471-
controller:Symfony\Bundle\FrameworkBundle\Controller\TemplateController
472-
defaults:
473-
# the path of the template to render
474-
template:'static/privacy.html.twig'
471+
# the path of the template to render
472+
template:'static/privacy.html.twig'
475473
476-
# special options defined by Symfony to set the page cache
477-
maxAge:86400
478-
sharedAge:86400
474+
# special options defined by Symfony to set the page cache
475+
maxAge:86400
476+
sharedAge:86400
479477
480-
# optionally you can definesomearguments passed to the template
481-
context:
482-
site_name:'ACME'
483-
theme:'dark'
478+
#somevariables passed to the template
479+
context:
480+
site_name:'ACME'
481+
theme:'dark'
484482
485483
..code-block::xml
486484
@@ -490,50 +488,46 @@ provided by Symfony:
490488
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
491489
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
492490
493-
<routeid="acme_privacy"
491+
<template-routeid="acme_privacy"
494492
path="/privacy"
495-
controller="Symfony\Bundle\FrameworkBundle\Controller\TemplateController">
496493
<!-- the path of the template to render -->
497-
<defaultkey="template">static/privacy.html.twig</default>
494+
template="static/privacy.html.twig"
498495
499496
<!-- special options defined by Symfony to set the page cache-->
500-
<defaultkey="maxAge">86400</default>
501-
<defaultkey="sharedAge">86400</default>
502-
503-
<!--optionally you can definesomearguments passed to the template-->
504-
<defaultkey="context">
505-
<defaultkey="site_name">ACME</default>
506-
<defaultkey="theme">dark</default>
507-
</default>
508-
</route>
497+
maxAge="86400"
498+
sharedMaxAge="86400">
499+
500+
<!-- somevariables passed to the template-->
501+
<context>
502+
<stringkey="site_name">ACME</string>
503+
<stringkey="theme">dark</string>
504+
</context>
505+
</template-route>
509506
</routes>
510507
511508
..code-block::php
512509
513510
// config/routes.php
514-
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
515-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
511+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
516512
517513
return function (RoutingConfigurator $routes) {
518514
$routes->add('acme_privacy', '/privacy')
519-
->controller(TemplateController::class)
520-
->defaults([
521-
// the path of the template to render
522-
'template' => 'static/privacy.html.twig',
523-
524-
// special options defined by Symfony to set the page cache
525-
'maxAge' => 86400,
526-
'sharedAge' => 86400,
527-
528-
// optionally you can define some arguments passed to the template
529-
'context' => [
530-
'site_name' => 'ACME',
531-
'theme' => 'dark',
532-
]
515+
// the path of the template to render and a context of variables passed to it
516+
->template('static/privacy.html.twig', [
517+
'site_name' => 'ACME',
518+
'theme' => 'dark',
533519
])
520+
// special options defined by Symfony to set the page cache
521+
->maxAge(86400)
522+
->sharedMaxAge(86400)
534523
;
535524
};
536525
526+
..versionadded::5.1
527+
528+
This short syntax was introduced in Symfony 5.1. Before you had to
529+
define the controller and specific route attributes using ``defaults``.
530+
537531
..versionadded::5.1
538532

539533
The ``context`` option was introduced in Symfony 5.1.

‎translation/locale.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ A better policy is to include the locale in the URL using the
9292
9393
// config/routes.php
9494
use App\Controller\ContactController;
95-
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
95+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
9696
9797
return function (RoutingConfigurator $routes) {
9898
$routes->add('contact', '/{_locale}/contact')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp