I have written a custom ACL class as an Action Helper. The class name is Controller_Helper_Acl, and is located in the file applications/controllers/helpers/acl.php. My problem is that my application is having difficulty locating the file.
I want to use the Action Helper Event Hooks, so I need to instantiate the class early. In my bootstrap.php I tried the Helper Broker's addPath() method, but that doesn't work when I use the new keyword. (Presumaly it just tells the broker where to find the files when the class is called on demand).
If I put a require_once in the bootstrap, then use the new keyword to instantiate Controllers_Helpers_Acl, it works fine, but I don't th开发者_如何转开发ink this is a workable solution (since I will have many Action Helpers in the directory).
I tried adding a path to the Autoloader with $loader->registerNamespace('Controllers_Helpers_'), and pluralizing the class name, however file is still not found. (Perhaps I have the wrong syntax?)
How do others solve this problem? I suspect that it's my inexperience with Autoloader that's the real problem.
You can also specify your Action Helper path in the application.ini:
resources.frontController.actionHelperPaths.My_Controller_Action_Helper = "My/Controller/Action/Helper"
You could specify this path in your Bootstrap.php as follows:
protected function _initAutoload() {
$autoLoader = Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => ''
);
$resourceLoader->addResourceType('controller', 'controllers/helpers/', 'Controller_Helper_');
$autoLoader->pushAutoloader($resourceLoader);
}
Hope this helps.
The file should be located at library/custmname/controller/helper/acl.php, class name should be Customname_Controller_Helper_Acl, to get access to it you need to register the namespace Customname at bootstrap either thru application.ini or hardcoded in index.php or Bootstrap.php, i would recomend using application.ini tough ( add this line autoloaderNamespaces[] = "Customname_"
. There are a big number of examples on how you can achive this ...
精彩评论