开发者

Loading custom resources in Zend Framework 2

I just started with Zend Framework 2.0 and wanted to load my own resources.

My own library PWS resides in the library folder.

To override the FrontController resource I have the following file PWS/Application/Resource/FrontController.php

<?php

namespace PWS\Application\Resource;

class FrontController extends \Zend\Application\Resource\FrontController
{

    public function init()
    {
        retur开发者_如何学运维n parent::init()
    }
}

In my application.ini I have the following relevant lines:

autoLoaderNamespaces.PWS = APPLICATION_PATH "/../library/PWS"
pluginPaths.PWS\Application\Resource\ = APPLICATION_PATH "/../library/PWS/Application/Resource"

The project uses modules but I don't think this should affect the problem.

When I debugged a class ResourceLoader (which contains hardcoded paths to the resources) was used to load the FrontController instead of my own resource.

It isn't urgent but annoying :)


Are resources case sensitive? I know it's "Frontcontroller" and not "FrontController".
Maybe give that a try? Not much else go to on here... :]

(This is from my experience with ZF1, not 2)


After some painful debugging i found a way of loading my custom resources.

In my bootstrap file i inserted the following function:

function _initResources() 
{
     $broker = $this->getBroker();
     $broker->getClassLoader()->registerPlugin('frontcontroller', 'PWS\Application\Resource\FrontController');
}

This replaces the hardcoded frontcontroller path in the ResourceLoader with my own class.

This is still not what i wanted, because this way i cannot load all the resources at once from my own resource namespace. And the pluginPaths variable in the application.ini doesnt do the job. But it is quicker this way because Zend doesn't have to iterate through a directory to find the right class.

Think I have to wait for the ZF2 release which contains some documentation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜