Reputation: 33
I'm using Symfony 2.8.0 (as I find Symfony 3.x not very mature at the moment, but let's not go into that discussion right now).
According to the official documentation (http://symfony.com/doc/2.8/book/templating.html#embedding-controllers) it should be possible to pass arguments to an embedded controller invoked from within a view.
However, this doesn't seem to work. I always end up with the following exception:
"Controller "AppBundle\Controller\DefaultController::buildNavigationAction()" requires that you provide a value for the "$argument1" argument (because there is no default value or because there is a non optional argument after this one)."
Within my view I have the following bit of code:
{{ render(controller('AppBundle:Default:buildNavigation'), {
'argument1': 25,
'argument2': 50
}) }}
The controller looks like this:
public function buildNavigationAction($argument1, $argument2)
{
// ... some logic ...
return $this->render(
'navigation.html.twig', array(
'foo' => $argument1,
'bar' => $argument2
)
);
}
What gives? Is this a bug?
The use case described in the documentation (rendering dynamic content from within the base template and therefor on every page) is exactly what I'm using it for. Repeating the same logic in every single controller is an obvious sin against the DRY principle.
Upvotes: 3
Views: 360
Reputation: 8276
Your syntax is incorrect, as you are not passing values to the controller since you are closing the )
too early. It should instead be:
{{ render(controller('AppBundle:Default:buildNavigation', {
'argument1': 25,
'argument2': 50
})) }}
Upvotes: 2