-- junggle <[EMAIL PROTECTED]> wrote
(on Thursday, 26 June 2008, 02:26 PM -0700):
> I'm using Zend_Controller_Action to create presentable objects
> (like page, sitemap, items, user...) which I then pass to Zend_View.
> Zend_View then creates response using specified template (html, xml, txt,
> ...)
> 
> I would like to know your opinion: 
> Where should the response's http headers be set ?
> 
> The View is responsible for presentation of the content and most of the
> headers
> I need to set are content-related (content-type, cache-control,
> content-language...).
> So I guess the headers could be set in the view's template. That would make
> my controllers much cleaner.
> 
> On the other hand, I'm not sure it is a good idea to use the templates for
> something else than just creating the html/xml/txt.

I usually setup response headers in the controller. However, some
purists would say that this is the responsibility of the view.
Regardless, you should set them _in your response object_ to ensure
encapsulation; this becomes even more important with the upcoming 1.6
release when the MVC testing infrastructure will be in place, as if you
use the response object, you can test to see what headers were set.

To set headers from the view, you can simply access the response object
via the front controller:
    
    Zend_Controller_Front::getInstance()->getResponse()->setHeader(...);

If you want to earn points, you could create a view helper that does
this for you (either retrieving the response or setting headers) and
propose it on the wiki for standard inclusion in the framework... ;-)

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to