Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Call to non-existing method in Zend\Di Definition code sample #1351

Open
Martin-P opened this issue Aug 12, 2014 · 1 comment
Open

Call to non-existing method in Zend\Di Definition code sample #1351

Martin-P opened this issue Aug 12, 2014 · 1 comment
Labels

Comments

@Martin-P
Copy link
Contributor

The first comment mentions 2 bugs in the documentation:

I have found two bugs in the documentation. At first, 'new Configuration' should be replaced with 'new Config' and the second thing is that there is no method 'setLocator' in the stable version of ZF2.

The Configuration to Config is already fixed in #1345.

The second bug needs a fix. I can confirm Zend\Mvc\Application::setLocator does not exist, but I'm not sure what the code should be. The current code is this:

protected function setupDi(Application $app)
{
    $definitionList = new DefinitionList(array(
        new Definition\ArrayDefinition(include __DIR__ . '/path/to/data/di/My_MovieApp-definition.php'),
        new Definition\ArrayDefinition(include __DIR__ . '/path/to/data/di/My_OtherClasses-definition.php'),
        $runtime = new Definition\RuntimeDefinition(),
    ));
    $di = new Di($definitionList, null, new Config($this->config->di));
    $di->instanceManager()->addTypePreference('Zend\Di\LocatorInterface', $di);
    $app->setLocator($di); // <---- this line is not correct
}
@Ocramius
Copy link
Member

@Martin-P the standard Zend\Mvc\Application allows you to configure Zend\Di as abstract factory backing the main Zend\ServiceManager\ServiceManager of the application.

The only supported way to use Zend\Di is to have an $app->getServiceManager()->get('Config')['di']

@Ocramius Ocramius added the bug label Aug 13, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants