开发者

Zend Framework: Need Auto Loading on IIS7 help

ZF is wearing me thin. I cannot get one instance of the AutoLoader to work without first using this to add it as a resource

require_once ('Zend\Loader\Autoloader.php');
Zend_Loader_Autoloader::getInstance();

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
           'basePath'  => APPLICATION_PATH . '/helpers',
           'namespace' => 'Application_',
       ));

$resourceLoader->addResourceType('form', 'forms/', 'Form')
           ->addResourceType('functions', 'functions/', 'Functions')开发者_Go百科
           ->addResourceType('menus', 'menus/', 'Menu')
           ->addResourceType('acls', 'acls/', 'Acls');

Now I am trying to load a plugin but ZF complains about the paths when I know the files exist.

// located in application/controllers/plugins
    require('controllers\plugins\Acl.php');
    $front = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new Application_Controller_Plugin_Acl($acl));

Why do I have to use require Is this a IIS7 thing? I thought the AutoLoader was supposed to take care of everything.


I don't think this is an IIS problem. I think this is a improper use of Zend_Loader_Autoloader_Resource.

You're telling the autoloader via Zend_Loader_Autoloader_Resource to add the namespace Application and that it is located in the basePath APPLICATION_PATH . '/helpers'.

From this if I try:

new Application_Menu_Primary();

ZF should find it in APPLICATION_PATH . '/helpers/menus/Primary.php'. Is that really where you want to find the file? I am guessing not. Further, trying this: Application_Controller_Plugin_Acl will never be included cause your missing the resource type Controller_Plugin and it's directory inside APPLICATION_PATH . '/helpers' (I doubt you want that).

I would suggest that you remove this usage of Zend_Loader_Autoloader_Resource all together and add your namespace into your application's /library directory and create the following directory structure:

/library/Application/Controller/Plugin/Acl.php
/library/Application/Form/
...etc

Then, you need to add /library path to your PHP include_path via index.php. (I thought this was standard)

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

Finally, add the Application namespace to your application.ini:

autoloaderNamespaces.app = 'Application'

That should clear up your problems. I suggest you learn more about the purpose of this class Zend_Loader_Autoloader_Resource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜