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

Appearance settings

Commit fce0f86

Browse filesBrowse files
committed
Add stateless route attribute documentation
1 parent 1e3df40 commit fce0f86
Copy full SHA for fce0f86

File tree

1 file changed

+78
-0
lines changed
Filter options

1 file changed

+78
-0
lines changed

‎routing.rst

Copy file name to clipboardExpand all lines: routing.rst
+78Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,84 @@ with a locale. This can be done by defining a different prefix for each locale
18051805
;
18061806
};
18071807
1808+
.. _stateless-routing:
1809+
1810+
Stateless Routes
1811+
----------------
1812+
1813+
.. versionadded:: 5.1
1814+
1815+
The ``stateless`` option was introduced in Symfony 5.1
1816+
1817+
Sometimes, when an HTTP response should be cached, it is important to ensure
1818+
that can happen. However, whenever session is started during a request, Symfony
1819+
turns the response into a private non-cacheable response.
1820+
1821+
For details, see :doc:`/http_cache`.
1822+
1823+
Routes can configure a ``stateless`` boolean option in order to declare that the
1824+
session shouldn't be used when matching a request:
1825+
1826+
.. configuration-block::
1827+
1828+
.. code-block:: php-annotations
1829+
1830+
// src/Controller/MainController.php
1831+
namespace App\Controller;
1832+
1833+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1834+
use Symfony\Component\Routing\Annotation\Route;
1835+
1836+
class MainController extends AbstractController
1837+
{
1838+
/**
1839+
* @Route("/", name="homepage", stateless=true)
1840+
*/
1841+
public function homepage()
1842+
{
1843+
// ...
1844+
}
1845+
}
1846+
1847+
.. code-block:: yaml
1848+
1849+
# config/routes.yaml
1850+
homepage:
1851+
controller: App\Controller\MainController::homepage
1852+
path: /
1853+
stateless: true
1854+
1855+
.. code-block:: xml
1856+
1857+
<!-- config/routes.xml -->
1858+
<?xml version="1.0" encoding="UTF-8" ?>
1859+
<routes xmlns="http://symfony.com/schema/routing"
1860+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1861+
xsi:schemaLocation="http://symfony.com/schema/routing
1862+
https://symfony.com/schema/routing/routing-1.0.xsd">
1863+
<route id="homepage" controller="App\Controller\MainController::homepage" path="/" stateless="true"/>
1864+
</routes>
1865+
1866+
.. code-block:: php
1867+
1868+
// config/routes.php
1869+
use App\Controller\MainController;
1870+
use Symfony\Bundle\FrameworkBundle\Routing\Loader\Configurator\RoutingConfigurator;
1871+
1872+
return function (RoutingConfigurator $routes) {
1873+
$routes->add('homepage', '/')
1874+
->controller([MainController::class, 'homepage'])
1875+
->stateless()
1876+
;
1877+
};
1878+
1879+
Now, if the session is used, the application will report it based on your
1880+
``kernel.debug`` parameter:
1881+
* ``enabled``: will throw an :class:`Symfony\\Component\\HttpKernel\\Exception\\UnexpectedSessionUsageException` exception
1882+
* ``disabled``: will log a warning
1883+
1884+
It well help you understanding and hopefully fixing unexpected behavior in your application.
1885+
18081886
.. _routing-generating-urls:
18091887

18101888
Generating URLs

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.