duanli4146 2012-03-02 17:08
浏览 49
已采纳

Zend Framework - 在注册表中找不到名称的插件

When calling a function in my views/helpers/ file, from my script inside views/scripts/ , i get this error:

Message: Plugin by name 'SetBlnCompany' was not found in the registry; used paths: My_View_Helper_: /www/zendserver/htdocs/development/application/views/helpers/ Zend_View_Helper_: Zend/View/Helper/:/www/zendserver/htdocs/development/application/views/helpers/

bootstrap.php

protected function _initConfig()
{       
    Zend_Registry::set('config', new Zend_Config($this->getOptions()));
    date_default_timezone_set('America/Chicago');
}

protected function _initAutoload() {     
    $autoloader = new Zend_Application_Module_Autoloader(array(             
        'namespace' => 'My',             
        'basePath'  => dirname(__FILE__),     
    ));
    return $autoloader;
} 

application.ini

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

application/views/helpers/DropdownHelper.php

class Zend_View_Helper_Dropdownhelper extends Zend_View_Helper_Abstract
{
     public $blnCompany = false;

     public function getBlnCompany() {
         return $this->blnCompany;
     }

     public function setBlnCompany($blnCompany) {
         $this->blnCompany = $blnCompany;
     }
}

script causing error

<?php 
     $this->setBlnCompany(true);
     //...etc...
?>

EDIT to add more background information to my post.

Ideally i would use this "dropdown helper" class, to have a function for "get html" a function for "get javascript" , and many setter functions to set options before the getHtml and getJavascript are called.

  • 写回答

1条回答 默认 最新

  • dougu4704 2012-03-02 17:12
    关注

    Your helper must have the same name than your method. Change Zend_View_Helper_Dropdownhelper into Zend_View_Helper_GetBlnCompany and it will work. Don't forget to change your filename too: GetBlnCompany.php

    In order to use a proxy method, you simply need to return $this;:

    // /application/views/helpers/helpers/GetBlnCompany.php
    class Zend_View_Helper_GetBlnCompany extends Zend_View_Helper_Abstract
    {    
        public function getBlnCompany() 
        {
            return $this;
        }
    
        public function fooBar($blnCompany)
        {
            return ucfirst($blnCompany);
        }
    }
    

    Then, you need to call your view helper as follow:

    $this->getBlnCompany()->fooBar('google');
    //return "Google"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料