8000 minor #10201 [Routing] Update routing.rst, add example routes as anno… · symfony/symfony-docs@91f6bd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91f6bd0

Browse files
committed
minor #10201 [Routing] Update routing.rst, add example routes as annotations (andreybolonin, weaverryan)
This PR was submitted for the 4.1 branch but it was merged into the 4.3 branch instead (closes #10201). Discussion ---------- [Routing] Update routing.rst, add example routes as annotations <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 54743d6 cleaning up some use statements, etc 0a1badf Update routing.rst
2 parents 076478c + 54743d6 commit 91f6bd0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

components/routing.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,22 @@ Annotation Routing Loaders
250250
Last but not least there are
251251
:class:`Symfony\\Component\\Routing\\Loader\\AnnotationDirectoryLoader` and
252252
:class:`Symfony\\Component\\Routing\\Loader\\AnnotationFileLoader` to load
253-
route definitions from class annotations. The specific details are left
254-
out here.
253+
route definitions from class annotations::
254+
255+
use Doctrine\Common\Annotations\AnnotationReader;
256+
use Symfony\Component\Config\FileLocator;
257+
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
258+
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
259+
260+
$loader = new AnnotationDirectoryLoader(
261+
new FileLocator(__DIR__.'/app/controllers/'),
262+
new AnnotatedRouteControllerLoader(
263+
new AnnotationReader()
264+
)
265+
);
266+
267+
$routes = $loader->load(__DIR__.'/app/controllers/');
268+
// ...
255269

256270
.. include:: /_includes/_annotation_loader_tip.rst.inc
257271

0 commit comments

Comments
 (0)
0