Skip to content

Instantly share code, notes, and snippets.

@manuakasam
Last active December 15, 2015 12:49
Show Gist options
  • Save manuakasam/5263154 to your computer and use it in GitHub Desktop.
Save manuakasam/5263154 to your computer and use it in GitHub Desktop.
Sample Injection
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