0

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.

Alfrekjv
  • 16,808
  • 1
  • 14
  • 4

1 Answers1

0

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.

Paul Dragoonis
  • 2,315
  • 1
  • 16
  • 22