Zend 覆盖默认视图对象

Zend 覆盖默认视图对象

问题描述:

如何覆盖 Zend 框架中的默认视图对象,以便我可以拥有自定义视图对象.

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;
}
}

默认视图包含模块的默认脚本路径.我想要所有模块的一条路径,以启用模板系统.setScriptPath 方法应该覆盖视图对象生成的默认路径,但它不会.

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

ArneRie 发布的内容是正确的,但是 ViewRenderer 会检查是否设置了标准脚本路径,如果没有则添加它.由于路径是后进先出检查,发生的事情是 ViewRenderer 在您的路径之后添加标准路径,然后始终使用该路径.

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.