4
votes

I have a Zend Framework application with a custom library which is namespaced (PHP 5.3).

I want to register a view helpers but I'm unable to do this due the namespace I use in the view helper.

Currently I in my bootstrap I have the following to register the Helper path:

protected function _initView()
{
    $view = new Zend_View();
    $view->addHelperPath(
        APPLICATION_PATH . "/../library/App/View/Helper",
        "App\View\Helper"
    );
}

The error that I get:

Zend_Loader_PluginLoader_Exception: Plugin by name 'IsActive' was not found in the registry; used paths: App\View\Helper_:

Does anybody has an idea how to register view helpers that are namespaced?

3
You mean PHP 5.3's namespaces or ZF's namespaces ? - user594791

3 Answers

4
votes

In my config, I use:

resources.view.helperPath.Glewz\View\Helper\ = APPLICATION_PATH "/../library/Glewz/View/Helper"

One thing I found was that I need to put in the constructor function since the view helper class name and the public function are the same, it will use that function as the constructor. This won't be a problem if you are using PHP 5.3.3 or above - http://php.net/manual/en/language.oop5.decon.php - "As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes. "

0
votes

In my bootstrap I use this:

$view->addHelperPath(APPLICATION_PATH . '/../library/App/View/Helper', 'App_View_Helper');

Additional: You can overload __call method in Zend_View_Abstract:

if ( method_exists($helper, $name) ) {
    $methodName = $name;
} else {
    $methodName = 'direct';
}

return call_user_func_array(array($helper, $methodName), $args);

See this

0
votes

I think that default ZF's autoloader can't work with namespaces. You could try write your own autoloader (or try to use that one) and register it as default.