Skip to content

Commit

Permalink
minor #5888 Removed the use of ContainerAware class (javiereguiluz)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xabbuh committed Nov 26, 2015
2 parents f247808 + b0cae3b commit 400873c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
25 changes: 7 additions & 18 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1397,25 +1397,14 @@ route. With this information, any URL can easily be generated::

.. note::

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

use Symfony\Component\DependencyInjection\ContainerAware;

class MainController extends ContainerAware
{
public function showAction($slug)
{
// ...

$url = $this->container->get('router')->generate(
'blog_show',
array('slug' => 'my-blog-post')
);
}
}
$url = $this->container->get('router')->generate(
'blog_show',
array('slug' => 'my-blog-post')
);

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

Expand Down
19 changes: 10 additions & 9 deletions cookbook/form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,25 +416,26 @@ it with :ref:`dic-tags-form-type`.
array('security.context')
);
If you wish to create it from within a controller or any other service that has
access to the form factory, you then use::
If you wish to create it from within a service that has access to the form factory,
you then use::

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

class FriendMessageController extends ContainerAware
In a controller that extends the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`
class, you can simply call::

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class FriendMessageController extends Controller
{
public function newAction(Request $request)
{
$form = $this->get('form.factory')->create('friend_message');
$form = $this->createForm('friend_message');

// ...
}
}

If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::

$form = $this->createForm('friend_message');

You can also easily embed the form type into another form::

// inside some other "form type" class
Expand Down

0 comments on commit 400873c

Please sign in to comment.