8

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.

adam
  • 2,930
  • 7
  • 54
  • 89
  • Just FYI, any classes you make that are not part of ZF should not start with `Zend_`. It would make someone think that your view helper is really built into ZF and adds an extra lookup for the autoloader. `Note: Important: Code that must be deployed alongside Zend Framework libraries but is not part of the standard or extras libraries (e.g. application code or libraries that are not distributed by Zend) must never start with "Zend_" or "ZendX_".` See [Zend Framework - Naming Conventions](http://framework.zend.com/manual/en/coding-standard.naming-conventions.html) – drew010 Mar 02 '12 at 18:57

1 Answers1

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"
Liyali
  • 5,643
  • 2
  • 26
  • 40
  • so a helper can only have one publicly usable function? – adam Mar 02 '12 at 17:14
  • thanks. 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. – adam Mar 02 '12 at 17:18
  • +1 For filename suggestion. Got this error when code developed on mac (case insensitive file system) was deployed to linux. – txyoji Oct 18 '13 at 17:47