8000 [Security] Document the `LogoutRouteLoader` · symfony/symfony-docs@e6bd0f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6bd0f9

Browse files
committed
[Security] Document the LogoutRouteLoader
1 parent c276932 commit e6bd0f9

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

security.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,53 @@ To enable logging out, activate the ``logout`` config parameter under your fire
18461846
;
18471847
};
18481848
1849-
Next, you need to create a route for this URL (but not a controller):
1849+
``path`` can be either a route name, or a URI.
1850+
1851+
Since Symfony 6.4, you can leverage the
1852+
:class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader`
1853+
to automatically register a route for every logout URI you configured.
1854+
If your project uses :ref:`Symfony Flex <symfony-flex>`,
1855+
this is already done for you.
1856+
Otherwise, you need to import the ``security.route_loader.logout`` service
1857+
as a routing resource:
1858+
1859+
.. configuration-block::
1860+
1861+
.. code-block:: yaml
1862+
1863+
# config/routes/security.yaml
1864+
logout:
1865+
resource: security.route_loader.logout
1866+
type: service
1867+
1868+
.. code-block:: xml
1869+
1870+
<!-- config/routes/security.xml -->
1871+
<?xml version="1.0" encoding="UTF-8" ?>
1872+
<routes xmlns="http://symfony.com/schema/routing"
1873+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1874+
xsi:schemaLocation="http://symfony.com/schema/routing
1875+
https://symfony.com/schema/routing/routing-1.0.xsd">
1876+
1877+
<import resource="security.route_loader.logout" type="service"/>
1878+
</routes>
1879+
1880+
.. code-block:: php
1881+
1882+
// config/routes/security.php
1883+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1884+
1885+
return static function (RoutingConfigurator $routes): void {
1886+
$routes->import('security.route_loader.logout', 'service');
1887+
};
1888+
1889+
.. versionadded:: 6.4
1890+
1891+
The :class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader` was
1892+
introduced in Symfony 6.4.
1893+
1894+
Another option is to create a route matching the name or URI you configured as
1895+
``path``. You don't have to associate a controller because it wouldn't be called:
18501896

18511897
.. configuration-block::
18521898

0 commit comments

Comments
 (0)
0