Skip to content

Removed the use of ContainerAware class #5888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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