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

Commit280a5c7

Browse files
committed
Add an example with@route
1 parent14f89d7 commit280a5c7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

‎controller/service.rst‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,64 @@ the route ``_controller`` value:
137137
fully-qualified class name (FQCN). See the
138138
`FrameworkExtraBundle documentation`_ for details.
139139

140+
For example, you could use annotations in the ``HelloController`` defined
141+
earlier::
142+
143+
// src/AppBundle/Controller/HelloController.php
144+
namespace AppBundle\Controller;
145+
146+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
147+
use Symfony\Component\HttpFoundation\Response;
148+
149+
class HelloController
150+
{
151+
/**
152+
* @Route("/hello")
153+
*/
154+
public function indexAction($name)
155+
{
156+
// ...
157+
}
158+
}
159+
160+
With the following routes:
161+
162+
..configuration-block::
163+
164+
..code-block::yaml
165+
166+
# app/config/routing.yml
167+
app:
168+
resource:"@AppBundle/Controller/"
169+
type:annotation
170+
171+
..code-block::xml
172+
173+
<!-- app/config/routing.xml-->
174+
<?xml version="1.0" encoding="UTF-8" ?>
175+
<routesxmlns="http://symfony.com/schema/routing"
176+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
177+
xsi:schemaLocation="http://symfony.com/schema/routing
178+
http://symfony.com/schema/routing/routing-1.0.xsd">
179+
180+
<!-- the type is required to enable the annotation reader for this resource-->
181+
<importresource="@AppBundle/Controller/"type="annotation"/>
182+
</routes>
183+
184+
..code-block::php
185+
186+
// app/config/routing.php
187+
use Symfony\Component\Routing\RouteCollection;
188+
189+
$collection = new RouteCollection();
190+
$collection->addCollection(
191+
// second argument is the type, which is required to enable
192+
// the annotation reader for this resource
193+
$loader->import("@AppBundle/Controller/", "annotation")
194+
);
195+
196+
return $collection;
197+
140198
..tip::
141199

142200
If your controller implements the ``__invoke()`` method, you can simply

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp