FriendsOfSymfony/FOSRestBundle — pull request #576 by merk (2013-10-06 05:47:37+00:00)
Title: [Proposal] Configuration to disable copying of default template variables

The way we copy default template variables can cause issues. For example:

```php
/**
* The routeParam is configured to be a parameter in the route (obviously :))
* @Rest\View
*/
public function putAction(Request $request, $routeParam)
{
// Do things with $request

$view = View::create('redirect_route');
$view->setStatusCode(Codes::HTTP_ACCEPTED);
$view->setLocation('/resource/123');

return $view;
}
```

FOSRestBundle at the moment will make the assumption that a template should be rendered for this response because the request object contains data ($routeParam) which is copied into the View object's data array by the ViewResponseListener. If the template doesn't exist, or relies on additional template variables that wont be set when you redirect, we end up with an exception from Twig.

In my opinion, this is not intended behaviour, and while I can understand in some cases you want the route parameters to be copied (for example, when using ParamConverters you will automatically get the parameters in the template to be rendered) I dont think its a desirable thing when you're handling data and may want to redirect somewhere else with a non 3xx status code.

ps. Sorry about reorganising the ViewResponseListenerTest file, I couldnt help but refactor it a bit :)