Skip to content

Commit 400873c

Browse files
committed
minor #5888 Removed the use of ContainerAware class (javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Removed the use of ContainerAware class | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #5884 Removing the use of `ContainerAware` in these examples required a heavy rewording. Please, review them. Thanks! Commits ------- b0cae3b Removed the use of ContainerAware class
2 parents f247808 + b0cae3b commit 400873c

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

book/routing.rst

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,25 +1397,14 @@ route. With this information, any URL can easily be generated::
13971397

13981398
.. note::
13991399

1400-
In controllers that don't extend Symfony's base
1401-
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`,
1402-
you can use the ``router`` service's
1403-
:method:`Symfony\\Component\\Routing\\Router::generate` method::
1400+
The ``generateUrl()`` method defined in the base
1401+
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class is
1402+
just a shortcut for this code::
14041403

1405-
use Symfony\Component\DependencyInjection\ContainerAware;
1406-
1407-
class MainController extends ContainerAware
1408-
{
1409-
public function showAction($slug)
1410-
{
1411-
// ...
1412-
1413-
$url = $this->container->get('router')->generate(
1414-
'blog_show',
1415-
array('slug' => 'my-blog-post')
1416-
);
1417-
}
1418-
}
1404+
$url = $this->container->get('router')->generate(
1405+
'blog_show',
1406+
array('slug' => 'my-blog-post')
1407+
);
14191408

14201409
In an upcoming section, you'll learn how to generate URLs from inside templates.
14211410

cookbook/form/dynamic_form_modification.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,26 @@ it with :ref:`dic-tags-form-type`.
416416
array('security.context')
417417
);
418418
419-
If you wish to create it from within a controller or any other service that has
420-
access to the form factory, you then use::
419+
If you wish to create it from within a service that has access to the form factory,
420+
you then use::
421421

422-
use Symfony\Component\DependencyInjection\ContainerAware;
422+
$form = $formFactory->create('friend_message');
423423

424-
class FriendMessageController extends ContainerAware
424+
In a controller that extends the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`
425+
class, you can simply call::
426+
427+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
428+
429+
class FriendMessageController extends Controller
425430
{
426431
public function newAction(Request $request)
427432
{
428-
$form = $this->get('form.factory')->create('friend_message');
433+
$form = $this->createForm('friend_message');
429434

430435
// ...
431436
}
432437
}
433438

434-
If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::
435-
436-
$form = $this->createForm('friend_message');
437-
438439
You can also easily embed the form type into another form::
439440

440441
// inside some other "form type" class

0 commit comments

Comments
 (0)