2013-04-29 106 views
0

我想在我的項目中添加一個視圖助手,但我發現了以下錯誤:Zend公司:自定義視圖助手

[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 

應用程序/視圖/助理/ LoggedInAs.php

class My_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract 
{ 
    public function loggedInAs() 
    { 
     //code 
    } 
} 

應用/ CONFIGS /的application.ini

resources.view[]= 
resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers" 

應用/佈局/腳本/ layout.phtml

echo $this->loggedInAs(); 

有計算器上其他一些問題,但這些並沒有爲我工作。

編輯1: 改變Zend_View_Helper_LoggedInAsMy_View_Helper_LoggedInAs添噴泉的回答 編輯後2: 完整的錯誤

回答

3

您所提供的答案似乎並沒有多大意義,如果你的意思是你添加<?php到文件的頂部你的班級寫在哪裏,我只能說「歡迎來到PHP!」否則以下內容可能對未來有所幫助......或不。

運用feibeck爲基準的主application.ini,我想出了:

//excerpt from application.ini 
resources.view.helperPath = APPLICATION_PATH "/views/helpers" 
resources.view.helperPathPrefix = "My_View_Helper" 

但是你正在使用的MVC的默認值,所以你應該不需要任何配置都沒有。

這可能是配置太多的情況。

話雖這麼說: 我從來沒有設置視圖選項在application.ini因爲我從來沒有很肯定的,我應該期待什麼效果的風扇(我在添加或設置選項?) 。我更喜歡設置視圖中引導作爲最常用的方法是更冗長,告訴一個更完整的故事:

//bootstrap.php 
protected function _initView() 
    { 
     //Initialize view 
     $view = new Zend_View(); 
     //add custom view helper path 
     $view->addHelperPath(APPLICATION_PATH . '/../library/My/View/Helper'); 
     //add custom script path for partials 
     $view->addScriptPath(APPLICATION_PATH . '/../library/My/View/Scripts/'); 
     //set css includes, path is relative to /public 
     $view->headlink()->setStylesheet('/bootstrap/css/bootstrap.css'); 
     //add javascript files, path is relative to /public 
     $view->headScript()->setFile('/bootstrap/js/jquery.min.js'); 
     $view->headScript()->appendFile('/bootstrap/js/bootstrap.min.js'); 
     //add it to the view renderer 
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
       'ViewRenderer'); 
     $viewRenderer->setView($view); 
     //Return it, so that it can be stored by the bootstrap 
     return $view; 
    } 

希望這提供了一些幫助。

+0

是的,我知道,愚蠢的是我沒有想到它。我已經在PHP中編寫了幾年,但現在我很困惑,現在我正在學習ZF;) – 2013-05-01 12:57:03

+0

不要讓ZF讓你感到困惑,它只是PHP。 (提示提示) :) – RockyFord 2013-05-02 11:56:37

0

類的名稱應該是My_View_Helper_LoggedInAs,因爲那是你宣佈什麼作爲的application.ini您的命名空間。 Zend命名空間僅適用於ZF類。

+0

可悲的是,沒有工作,同樣的錯誤。 – 2013-04-29 12:30:51

+0

你能編輯你的問題以包含完整的錯誤嗎?它還應該列出它嘗試的路徑和命名空間 – 2013-04-29 12:32:37

+0

查看完整錯誤的第一個代碼塊 – 2013-04-29 12:40:28

0

我修復了一個奇怪的解決方案,因爲我在互聯網上找不到像這樣的東西。 我只是在應用/視圖/傭工開始加入<?PHP/LoggedInAs.php