Model Table Inside Another Module

i have two modules called: Autenticacao and Utilizadores.

In my AutenticacaoController, i want to access to UserTable, which is inside the module Utilizadores:

image

any example of this?

Code AutenticacaoController:

private $usersTable;
public function __construct(UserTable $usersTable) {
   $this->usersTable = $usersTable;
}

public function getusersAction(): JsonModel {
   $this->usersTable->getAll(); //<- not working, because UserTable is not accessible
   return new JsonModel();
}

Thanks

Welcome to the forums! :slight_smile:


You are going to need to create a factory for your controller.

There’s this guide.
You’re about here in that guide, the next step would be to create the factory and link it to the controller through configuration as outlined here.

This is not mandatory, because it can also be done more simply: use the reflection factory of laminas-servicemanager.

Make sure that the class UserTable is registered for the service manager, then you can use:

namespace Autenticacao;

use Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\AutenticacaoController::class => ReflectionBasedAbstractFactory::class,
        ],
    ],
    // …
];

This is not mandatory, because it can also be done more simply: use the reflection factory of laminas-servicemanager.

Well, TIL :smiley: