Zend overwrite default view object

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:23:42

问题


How can i overwrite the default view object in zend framework so i could have the custom one.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

function _initViewHelpers() { 
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('HTML4_STRICT');
    $view->setHelperPath(APPLICATION_PATH . '/helpers', '');        
    $view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
                     ->appendName('description', 'Zend Framework');
    $view->headTitle()->setSeparator(' - ');
    $view->headTitle('Zend Custom View');
    $view->setScriptPath(APPLICATION_PATH . '/themes/admin');

    return $view;
}
}

The default view is contains default script path for module. I want one path for all module, to enable template system. The setScriptPath method should overwrite the default path generated by the view object, but it doesn't.

array(2) { [0]=> string(66) "C:/xampp/htdocs/NEOBBS_v6/application/modules/admin/views\scripts/" [1]=> string(51) "C:\xampp\htdocs\NEOBBS_v6\application/themes/admin/" }

it has two scriptPath. Can this be done by overwriting the default view object ? How can i do that, thanks for advanced


回答1:


What ArneRie posted is correct, however the ViewRenderer checks to see whether the standard script path is set and adds it if not. Since the paths are checked LIFO, what's happening is that the ViewRenderer is adding the standard path after your one and then always using that one.

What worked for me was to set both the standard path and my custom path at the same time, with the custom one being last, something like:

$view->setScriptPath(array(
    APPLICATION_PATH . '/views/scripts/', // or whatever the standard path is
    APPLICATION_PATH . '/themes/admin'
));

there may be a better solution for this though.




回答2:


Try to add:

        $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
        $viewRenderer->setView($view);
        Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);


来源:https://stackoverflow.com/questions/6069488/zend-overwrite-default-view-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!