FriendsOfSymfony/FOSRestBundle — Issue #140: Call to undefined method ...getTemplate()
Author: tarjei
Created: 2011-10-14 11:43:26+00:00
State: open

Hi, after upgrading FOSRestBundle I get this error:
Fatal error: Call to undefined method Symfony\Bundle\FrameworkBundle\Templating\TemplateReference::getTemplate() in /home/tarjei/Zero/ZeroCMS/vendor/bundles/Sensio/Bundle/FrameworkExtraBundle/EventListener/TemplateListener.php on line 63

This happens when I do a request for a route handled by the FOSRestBundle. I'm not sure how it happens but the
Request->attributes['_template'] attribute gets changed from a Template to a TemplateReference.

This happens because TemplateListener::onKernelController() gets called twice. First as a normal event and then when ViewResponseListener::onKernelController() calls parent::onKernelController().

This happens as a result of this commit:
https://github.com/FriendsOfSymfony/FOSRestBundle/commit/a30a28d6709ff712735cdb8e9e4c74b95613adb8

I'm not sure what the best way to solve this conundrum is, therefore bugreport instead of patch.

I got two temporary solutions:

1. disable parent::onKernelController() in ViewResponseListener::onKernelController()

2. add

if ($configuration instanceof TemplateReference) {
return;
}

To TemplateListener ca line 62.