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

ada*_*dam 8 php zend-framework view view-helpers

views/scripts /中的脚本调用views/helpers / file中的函数时,我收到此错误:

消息:在注册表中找不到名称为"SetBlnCompany"的插件; 使用的路径: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;
} 
Run Code Online (Sandbox Code Playgroud)

的application.ini

resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers" 
Run Code Online (Sandbox Code Playgroud)

应用程序/视图/助理/ 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;
     }
}
Run Code Online (Sandbox Code Playgroud)

脚本导致错误

<?php 
     $this->setBlnCompany(true);
     //...etc...
?>
Run Code Online (Sandbox Code Playgroud)

编辑以添加更多背景信息到我的帖子.

理想情况下,我会使用这个"dropdown helper"类,为"get jtml"提供一个"获取javascript"函数的函数,以及在调用getHtml和getJavascript之前设置选项的许多setter函数.

Liy*_*ali 11

您的助手必须与您的方法具有相同的名称.更改Zend_View_Helper_DropdownhelperZend_View_Helper_GetBlnCompany,它会工作.不要忘记更改文件名:GetBlnCompany.php

要使用代理方法,您只需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);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,您需要调用您的视图助手,如下所示:

$this->getBlnCompany()->fooBar('google');
//return "Google"
Run Code Online (Sandbox Code Playgroud)