pix*_*xel 2 resources zend-framework application-resource
我创建了自定义应用程序资源:
class Custom_Entitymanager extends Zend_Application_Resource_ResourceAbstract{
//...
public function init (){
//...
$em = \Doctrine\ORM\EntityManager::create($options['connection'], $config);
return $em;
}
}
Run Code Online (Sandbox Code Playgroud)
我把它放在MyProject\library\Custom\Entitymanager.php档案里
当我想要检索时Entitymanager使用:
$em = $this->getInvokeArg('bootstrap')->getResource('entityManager');
Run Code Online (Sandbox Code Playgroud)
我得到null对象.
如何在application.ini文件中注册我的自定义应用程序资源?
在application/configs/application.ini:
pluginpaths.Custom_ = APPLICATION_PATH "/../library/Custom"
resources.EntityManager[] =
Run Code Online (Sandbox Code Playgroud)
旁注:我可能会将EntityManager类更深入地推入我自己的自定义库中,或许类似于Custom_Application_Resource_EntityManager.在这种情况下,上面的路径映射将更改为:
pluginpaths.Custom_Application_Resource_ = APPLICATION_PATH "/../library/Custom/Application/Resource"
resources.EntityManager[] =
Run Code Online (Sandbox Code Playgroud)