claudio3949
claudio3949

Reputation: 27

Get request parameter in embedding controller

In Symfony1 i can:

blog:
  url:   /blog/slug
  param: { module: blog, action: index }

and in action/controller i can get slug with: $request->getParameter('slug');

In Symfony2:

blog:
    path:      /blog/{slug}
    defaults:  { _controller: AcmeBlogBundle:Blog:show }

and i create "components" same as Symfony1 - http://symfony.com/doc/current/book/templating.html#templating-embedding-controller

How can i get slug in embedding controller? I tried:

$request->query->get('foo');
$request->request->get('bar');

but this still return null. In AcmeBlogBundle:Blog:show controller working ok.

Upvotes: 0

Views: 350

Answers (1)

Ken Hannel
Ken Hannel

Reputation: 2748

The param converter will populate the argument with the string from the route. So here is what your method looks like.

class BlogController extends Controller {
    public function showAction($slug) {
        // $slug will contain the value of the string from the route
    }
}

So if you wanted to embed this into a twig template it would look like this:

{{ render( controller('AcmeBlogBundle:Blog:show', {'slug': 'this-is-the-slug' })) }}

or from another controller

$this->render('AcmeBlogBundle:Blog:show.html.twig', array('slug' => 'this-is-the-slug'));

Upvotes: 2

Related Questions