我正在尝试在我的项目中添加一个View帮助器,但是我收到以下错误:
[Mon Apr 29 14:36:19 2013] [error] [client 10.0.0.26] PHP Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'LoggedInAs' was not found in the registry; used paths:\nMy_View_Helper_: /var/www/html/test-project/application/views/helpers/\nZend_View_Helper_: Zend/View/Helper/:/var/www/html/test-project/application/views/helpers/' in /usr/share/php/Zend/Loader/PluginLoader.php:412\nStack trace:\n#0 /usr/share/php/Zend/View/Abstract.php(1182): Zend_Loader_PluginLoader->load('LoggedInAs')\n#1 /usr/share/php/Zend/View/Abstract.php(618): Zend_View_Abstract->_getPlugin('helper', 'loggedInAs')\n#2 /usr/share/php/Zend/View/Abstract.php(344): Zend_View_Abstract->getHelper('loggedInAs')\n#3 /var/www/html/test-project/application/layouts/scripts/layout.phtml(16): Zend_View_Abstract->__call('loggedInAs', Array)\n#4 /var/www/html/test-project/application/layouts/scripts/layout.phtml(16): Zend_View->loggedInAs()\n#5 /usr/share/php/Zend/View.php(108): include('/var/www/html/t...')\n#6 /usr/share/php/Zend/View/Abstract.php(888): Zend_View->_run('/var/www/html/ in / /usr/share/php/Zend/Controller/Plugin/Broker.php on line 336
application/views/helpers/LoggedInAs.php
class My_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract
{
public function loggedInAs()
{
//code
}
}
application/configs/application.ini
resources.view[]=
resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers"
application/layouts/scripts/layout.phtml
echo $this->loggedInAs();
stackoverflow还有其他一些问题,但这些问题对我来说都不起作用 .
在Tim Fountain的回答之后 edit 1: 将 Zend_View_Helper_LoggedInAs
更改为 My_View_Helper_LoggedInAs
edit 2: 完整错误
3 回答
你提供的答案似乎没有多大意义,如果你说你将
<?php
添加到你的课程所在的文件的顶部,我只能说"Welcome to PHP!"否则以后可能会有所帮助...或者不 .使用feibeck中的主
application.ini
作为参考,我提出:但是你使用MVC的默认值,所以你根本不需要任何配置 .
这可能是配置太多的情况 .
That being said: 我从未喜欢在
application.ini
中设置视图选项,因为我从来不确定我应该期待什么效果(我是添加还是设置选项?) . 我更喜欢在bootstrap中设置视图,因为大多数使用的方法都比较冗长,并且讲述了一个更完整的故事:希望这能提供一些帮助 .
类名应为
My_View_Helper_LoggedInAs
,因为这是您在application.ini中声明的命名空间 . Zend命名空间仅适用于ZF类 .我用一个奇怪的解决方案修复它,因为我在互联网上找不到这样的东西 . 我刚刚在 application/views/helpers/LoggedInAs.php 的开头添加了
<?PHP