Heya, No, you have to keep a reference to the service manager. The whole point of doing that is to avoid having singletons or global/static variables that would pollute the environment and make things such as 2 ServiceManagers with different services very very hard to achieve.
I suggest you to pass the service manager (at instantiation time) to whatever object should be using it (or even better just pass what the object really needs to the object). You can read up more about it on http://framework.zend.com/manual/2.0/en/modules/zend.service-manager.quick-start.htmlin section "Creating a ServiceLocator-aware class" Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 13 December 2012 16:32, saiman [via Zend Framework Community] < [email protected]> wrote: > Hi all, > Is it possible to create one instance of the service manager and use it > everywhere? > For example I want to do following in my index.php: > > $serviceManager = new ServiceManager(); > $serviceManager->setService('dbAdapter', $adapter); > > And then somewhere in my project (OneOfMyLibraries.php) to get the > database instance, like: > > $serviceManager = new ServiceManager(); > $dbh = $serviceManager->get('dbAdapter'); > > Unfortunately this is not possible the second instance it's not related > wit the first one. Any idea how to proceed or what to use? > > Regards, > S. > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://zend-framework-community.634137.n4.nabble.com/ZF2-Using-ServiceManager-tp4658461.html > To start a new topic under Zend Framework, email > [email protected] > To unsubscribe from Zend Framework Community, click > here<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=634137&code=b2NyYW1pdXNAZ21haWwuY29tfDYzNDEzN3wxNzE0OTI1MTk4> > . > NAML<http://zend-framework-community.634137.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Re-ZF2-Using-ServiceManager-tp4658466.html Sent from the Zend Framework mailing list archive at Nabble.com.
