Last active
December 15, 2015 12:49
-
-
Save manuakasam/5263154 to your computer and use it in GitHub Desktop.
Sample Injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getServiceConfig() | |
{ | |
return array( | |
'factories' => array( | |
'my-model' => function($sm) { | |
$model = new \My\Model($sm); | |
return $model; | |
} | |
) | |
); | |
} | |
class Model { | |
protected $serviceManager; | |
public function __construct(ServiceManager $serviceManager) { | |
$this->serviceManager = $serviceManager; | |
} | |
public function someFunction() { | |
$dependency = $this->serviceManager->get('my-dependency'); | |
} | |
} | |
someControllerAction() { | |
$model = $this->getServiceLocator()->get('my-model'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment