Zend_View和addHelperPath

时间:2011-01-31 15:46:28

标签: php zend-framework helper

使用空Zend_View和addHelperPath时出现问题。 有人知道

之间的区别
$view = Zend_Layout::getMvcInstance()->getView();
$view->addHelperPath(
    APPLICATION_PATH . '/views/helpers/layouts', 
   'FOO_View_Helper'
);

$view = new Zend_View;
$view->addHelperPath(
    APPLICATION_PATH . '/views/helpers/layouts', 
    'FOO_View_Helper'
);
Zend_Layout::getMvcInstance()->setView($view);
$helper = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$helper->setView($view);

使用第一个示例,我的视图帮助程序已加载。第二个例子说

Plugin by name 'PriceOutput' was not found in the registry; used paths:
    Zend_View_Helper_: Zend/View/Helper/;./views\helpers/

我添加了

echo "<xmp>", var_dump($registry), "</xmp>";

in

PluginLoader::load($name, $throwExceptions = true)

和helperPaths都在同一个地方。但是使用第二个示例,ZF似乎只在Zend_View_Helper中搜索而不在FOO_View_Helper中搜索。

有什么想法吗?

就像我告诉的那样,第一个例子看了FOO_View_Helper,第二个例子不是: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'FooBar' was not found in the registry; used paths: FOO_View_Helper_: C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/basket/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/globallayer/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/globallayer/help/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/globallayer/styleinfolayer/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/layout/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/nys/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/overview/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/search/;C:\Programme\Zend\Apache2\htdocs\trunk_webshop\application/views/helpers/singleproductview/;C:\Programme\Zend in C:\Programme\Zend\Apache2\htdocs\trunk_core_webshop\library\Zend\Loader\PluginLoader.php on line 414

($ view-&gt; getHelperPaths()应该更好:P)

1 个答案:

答案 0 :(得分:2)

有了这个

$view = Zend_Layout::getMvcInstance()->getView();
$view->addHelperPath(
    APPLICATION_PATH . '/views/helpers/layouts', 
   'FOO_View_Helper'
);

您正在获取现有视图并设置路径,这是正确的。

但是在第二个示例中,您将创建一个新视图,然后设置路径,从而替换Bootstrap自动(和正确)加载的现有View。这个新的视图不知道你的Bootstrap,因此不知道你的自动加载器 - 因此错误。