So, I have an Admin module which houses all the Controllers such as Users, Usergroups, Products etc. In the Module.php there is the getServiceConfig() method which sets all the appropriate database tables for the controllers. This is fine.
My problem is with the Models (User.php and UserTable.php, for ex.). I ideally want these to come from their own independent modules so the Admin module is not completely overwhelmed with files.
When I write Module.php like this:
<?php
namespace Admin;
use User\Model\User;
use User\Model\UserTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Authentication\Adapter\DbTable as DbTableAuthAdapter;
class Module implements AutoloaderProviderInterface {
//Some other methods
public function getServiceConfig() {
return array(
'factories' => array(
'User\Model\UserTable' => function($sm) {
$tableGateway = $sm->get('UserTableGateway');
$table = new UserTable($tableGateway);
return $table;
},
'UserTableGateway' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new User());
return new TableGateway('user', $dbAdapter, null, $resultSetPrototype);
},
I get a blank page with dies not executing after it tries to initialize UserTable and User in getServiceConfig method. So, it is definitely a problem with those. It works fine if these classes are in the Admin module.
Ctrl-clicking the classes work so it is finding them. Is there any way to call these from the Admin's Module.php? Thanks.
getAutoloaderConfig
method from Admin and UserModule
class. – Gabriel