Is it possible to access an Entity/Storage Class from another Module, or should I create the same classes in each module that requires them?
Thanks.
Is it possible to access an Entity/Storage Class from another Module, or should I create the same classes in each module that requires them?
Thanks.
You should set up your storage classes as 'Services' in your module's Module.php file, under the getServiceConfig() method.
public function getServiceConfig()
{
return array('factories' => array(
'user.storage' => function($sm) {
return new \UserModule\Storage\User($sm->get('datasource'));
}
);
}
Now the service 'user.storage' exists system-wide and you can use it within any other service declaration using $sm->get('user.storage'), or from your controllers you can call getService() to obtain your services.
public function indexAction()
{
$us = $this->getService('user.storage');
$user = $us->getByID($this->getRouteParam('id'));
$this->render('UserModule:index:index.html.php', compact('user'));
}
Hope this helps. Thanks.