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

标签 php zend-framework view view-helpers

当调用我的views/helpers/ 文件中的函数时,从我在views/scripts/ 中的脚本> ,我得到这个错误:

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;
     }
}

导致错误的脚本

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

编辑以在我的帖子中添加更多背景信息。

理想情况下,我会使用这个“下拉助手”类,有一个用于“获取 html”的函数,一个用于“获取 javascript”的函数,以及许多用于在调用 getHtml 和 getJavascript 之前设置选项的 setter 函数。

最佳答案

您的助手必须与您的方法同名。将 Zend_View_Helper_Dropdownhelper 更改为 Zend_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);
    }
}

然后,您需要按如下方式调用您的 View 助手:

$this->getBlnCompany()->fooBar('google');
//return "Google"

关于php - Zend Framework - 在注册表中找不到按名称命名的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537419/

相关文章:

php - PHP 的 MySQL password() 函数

php - 使用 zend_navigation 的 zend headtitle

.net - 使用 .NET ListView 高效搜索数十万条记录

php - 大括号 {} 在 SQL 查询中做什么?

php - 如何更改 magento 管理 url 和端口,magento 运行清漆

php - 我可以在 PHP 中混合使用 MySQL API 吗?

php - Magento Questions 获取客户详细信息并且 onepage/checkout/success 不发送电子邮件

php - 阻止访问页面 Zend Framework

java - 如何创建此自定义 View

javascript - AngularJS 和 CSS 过渡