someuser
someuser

Reputation: 2299

Symfony2 - Do not render a view from controller like ZF setNoRender

Relatively new convert to Symfony2 from ZF1.

I have Googled and cannot seem to find the answer. Just wondering if there is a way to not render a view from a controller action in Symfony2.

In a ZF controller I could use:

$this->_helper->viewRenderer->setNoRender(true);

What is the equivalent in Symfony2?

Upvotes: 0

Views: 3553

Answers (2)

Martin Fasani
Martin Fasani

Reputation: 823

Wanted to give my Opinion: Just because there is a possibility to render(ControllerMethod,{ params}) in a template doesn't mean you have to use it.

Doing so leads almost always to a shitty architecture, the turning point where projects start to be hard to debug, since you are mixing a VIEW (Presentation layer) with a CONTROLLER, that in turn renders another VIEW. You get the point.

Then when you have an error in the ControllerMethod, and instead you get a template error, not so nice isn't it ?

I vouch for strong architecture in software projects. This cheap solutions, like using this commodities, lead to the start of the bad. And I suggest to avoid it as much as you can unless there is no other possible way. And certainly there is! That is the reason to use MVC. To separate Code from Presentation layer, start mixing both, and your architecture will leak.

Upvotes: 0

Jakub Zalas
Jakub Zalas

Reputation: 36191

In Symfony nothing is rendered for you automatically. If you need to render something, you have to do it explicitly. If you don't want to render, just don't do it :) Simply return a response:

return new Response();

Only job of a Symfony controller is to return a response. Rendering a template actually creates a response as well.

Upvotes: 4

Related Questions