Search code examples
zend-frameworkresourcesapplication-resource

How to register custom application resources in application.ini in Zend Framework 1.11.x


I have created custom aplication resource:

class Custom_Entitymanager extends Zend_Application_Resource_ResourceAbstract{
    //...
    public function init (){
        //...
        $em = \Doctrine\ORM\EntityManager::create($options['connection'],  $config);
        return $em;
    }
}

and I put it in MyProject\library\Custom\Entitymanager.php file.

When I want to retrieve Entitymanager using:

$em = $this->getInvokeArg('bootstrap')->getResource('entityManager');

I get null object.

How can I register my custom application resource in application.ini file?


Solution

  • In application/configs/application.ini:

    pluginpaths.Custom_ =  APPLICATION_PATH "/../library/Custom"
    resources.EntityManager[] =
    

    Side note: I'd probably push the EntityManager class down a little deeper into my own custom library, perhaps something like Custom_Application_Resource_EntityManager. In this case, the path mapping above would change to:

    pluginpaths.Custom_Application_Resource_ =  APPLICATION_PATH "/../library/Custom/Application/Resource"
    resources.EntityManager[] =