Reputation: 642
I get this message regardless of the path used and even if I place the class file in the default directory location.
Zend_Controller_Action_HelperBroker::addPath('./Plugins/Helpers','Helper');
Sorry, An error has occured: Application Error:exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'FormLoader' was not found in the registry; used paths:
Zend_Controller_Action_Helper_: Zend/Controller/Action/Helper/' in C:\PHP\Zendframework\Zend\Loader\PluginLoader.php:412
Stack trace:
#0 C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php(366): Zend_Loader_PluginLoader->load('FormLoader')
#1 C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php(293): Zend_Controller_Action_HelperBroker::_loadHelper('FormLoader')
#2 C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php(323): Zend_Controller_Action_HelperBroker->getHelper('formLoader')
#3 D:\websites\maklare.easypic.se\appfiles\application\controllers\UserController.php(13): Zend_Controller_Action_HelperBroker->__call('formLoader', Array)
#4 D:\websites\maklare.easypic.se\appfiles\application\controllers\UserController.php(13): Zend_Controller_Action_HelperBroker->formLoader('login')
#5 C:\PHP\Zendframework\Zend\Controller\Action.php(513): UserController->indexAction()
#6 C:\PHP\Zendframework\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#7 C:\PHP\Zendframework\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 C:\PHP\Zendframework\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#9 D:\websites\maklare.easypic.se\index.php(23): Zend_Controller_Front::run('D:\websites\mak...')
#10 {main}
Next exception 'Zend_Controller_Action_Exception' with message 'Action Helper by name FormLoader not found' in C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php:369
Stack trace:
#0 C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php(293): Zend_Controller_Action_HelperBroker::_loadHelper('FormLoader')
#1 C:\PHP\Zendframework\Zend\Controller\Action\HelperBroker.php(323): Zend_Controller_Action_HelperBroker->getHelper('formLoader')
#2 D:\websites\maklare.easypic.se\appfiles\application\controllers\UserController.php(13): Zend_Controller_Action_HelperBroker->__call('formLoader', Array)
#3 D:\websites\maklare.easypic.se\appfiles\application\controllers\UserController.php(13): Zend_Controller_Action_HelperBroker->formLoader('login')
#4 C:\PHP\Zendframework\Zend\Controller\Action.php(513): UserController->indexAction()
#5 C:\PHP\Zendframework\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#6 C:\PHP\Zendframework\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#7 C:\PHP\Zendframework\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#8 D:\websites\maklare.easypic.se\index.php(23): Zend_Controller_Front::run('D:\websites\mak...')
#9 {main}
The loader code:
<?php
/**
* Action Helper for loading forms
*
* @uses Zend_Controller_Action_Helper_Abstract
*/
class My_Helper_FormLoader extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Loader_PluginLoader
*/
public $pluginLoader;
/**
* Constructor: initialize plugin loader
*
* @return void
*/
public function __construct()
{
$this->pluginLoader = new Zend_Loader_PluginLoader();
}
/**
* Load a form with the provided options
*
* @param string $name
* @param array|Zend_Config $options
* @return Zend_Form
*/
public function loadForm($name, $options = null)
{
$module = $this->getRequest()->getModuleName();
$front = $this->getFrontController();
$default = $front->getDispatcher()
->getDefaultModule();
if (empty($module)) {
$module = $default;
}
$moduleDirectory = $front->getControllerDirectory($module);
$formsDirectory = dirname($moduleDirectory) . '/forms';
$prefix = (('default' == $module) ? '' : ucfirst($module) . '_')
. 'Form_';
$this->pluginLoader->addPrefixPath($prefix, $formsDirectory);
$name = ucfirst((string) $name);
$formClass = $this->pluginLoader->load($name);
return new $formClass($options);
}
/**
* Strategy pattern: call helper as broker method
*
* @param string $name
* @param array|Zend_Config $options
* @return Zend_Form
*/
public function direct($name, $options = null)
{
return $this->loadForm($name, $options);
}
}
?>
The bootstrap;
<?php
require 'appfiles\helpers\fb_sdk\src\facebook.php';
#------------------------------
# Get the paths set
#------------------------------
define('ROOT', realpath(dirname(__FILE__) . '/appfiles'));
#------------------------------
# Register the Zend autolaoder
#------------------------------
require_once ('Zend\Loader\Autoloader.php');
Zend_Loader_Autoloader::getInstance();
#------------------------------
# Dispatch
#------------------------------
require_once('appfiles\functions\functions.php');
Zend_Controller_Front::run( ROOT . '/application/controllers' );
Zend_Controller_Action_HelperBroker::addPath( ROOT .'/helpers');
?>
Upvotes: 2
Views: 2879
Reputation: 642
Okay, I came to two conclusions (actually three but...) The first is I think that the Broker is seriously broken since it does not responded to any changes in code. It only defaults when something does not work and that default in itself does not work.
Secondly, I went with Zend_Loader_Autoloader_Resource because it was closer to what I needed which was to be able to have an application specific library. It enforces Zend naming conventions but this is okay because it works!! :)
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => ROOT . '/helpers',
'namespace' => 'AppFiles',
));
$resourceLoader->addResourceType('acl', 'acls/', 'Acl')
->addResourceType('form', 'forms/', 'Form')
->addResourceType('model', 'models/', 'Model');
Thanks All! for your help and input
Upvotes: 0
Reputation: 164798
You can configure action helper paths in your configuration file.
If say your My_Helper_FormLoader
class was to be found at APPLICATION_PATH . '/Plugins/Helper/FormLoader.php'
resources.frontController.actionHelperPaths.My_Helper = APPLICATION_PATH "/Plugins/Helper"
Upvotes: 0
Reputation: 5932
If you want to be safe when adding the helpers, use an absolute path instead of a relative, and make sure you add the helper's prefix correctly:
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH '/Plugins/Helpers','Plugins_Helper');
or alternatively, try adding the helper with the AddBroker() function:
Zend_Controller_Action_HelperBroker::addPrefix('Plugins_Helper');
Zend_Controller_Action_HelperBroker::addHelper(new Plugins_Helper_FormLoader());
Note that it's important to name the helper classes correctly so the zend_autoloader can load them
Upvotes: 2