設定Zend_Form輸出XHTML

如果你有使用過Zend_Form就會發現由它所輸出的並不是XHTML,所以我們需要使用view helper來幫我們實現。你可以直接在view的版面中加入以下view helper,就可以達到我們想要的效果:
echo $this->doctype('XHTML1_STRICT');

最方便的方式就是直接在controller的plugin加入動作:
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
 Zend_Layout::startMvc();
 $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
 $viewRenderer->init();
 $view = $viewRenderer->view;
 $view->doctype('XHTML1_STRICT');
 $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
}
這樣就會將每個輸出的頁面設定為XHTML格式,而且還預設content type和charset.

沒有留言: