0
votes

When dealing with the Sylius e-commerce bundles I have found what seems to be a way of configurig the template for a route, that I didn't know:

I have tested in a fresh Symfony RC 2.2.0 with vendors installation. This would be in the routing.yml

_welcome:
    pattern:  /
    defaults:
      _controller: AcmeDemoBundle:Welcome:index
      _template: AcmeDemoBundle:Welcome:index # added by me

this generates an error:

FatalErrorException: Error: Call to a member function getTemplate() on a non-object in .... \vendor\sensio\framework-extra-bundle\Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener.php line 62

now, in TemplateListener, what we have is:

    if (!$configuration = $request->attributes->get('_template')) {
        return;
    }


    if (!$configuration->getTemplate()) {
        $guesser = $this->container->get('sensio_framework_extra.view.guesser');
        $configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
    }

$configuration is a String, actually the template I put in routing.yml (AcmeDemoBundle:Welcome:index). Checked by adding a var_dump and also inspecting ParameterBag -> get method which is what $request->attributes is.

So. Why TemplateListener is expecting an object? What am I missing? Am I missconfiguring in routing.yml?

1

1 Answers

2
votes

This parameter is not available in Symfony itself.

Feature is provided by SyliusResourceBundle and available only in Sylius controllers. And apparently _template request attribute conflicts with SensioFrameworkExtraBundle, which uses same name to store object.

We have to move those parameters one config node deeper, to avoid such problems in future. You can keep an eye on the https://github.com/Sylius/SyliusResourceBundle repository, fix should arrive today.