Here is an example of how I accomplished this. My module name is Application and the two tables I'm fetching data from are 'projects' and 'users'.
Module.php
namespace Application;
// Project db
use Application\Model\Project;
use Application\Model\ProjectTable;
// User db
use Application\Model\User;
use Application\Model\UserTable;
// db connection
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module {
public function onBootstrap(MvcEvent $e) {...}
public function getConfig() {...}
public function getAutoloaderConfig() {...}
public function getServiceConfig() {
return array(
'factories' => array(
'Application\Model\ProjectTable' => function($sm) {
$tableGateway = $sm->get('ProjectTableGateway');
$table = new ProjectTable($tableGateway);
return $table;
},
'ProjectTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Project());
return new TableGateway('projects', $dbAdapter, null, $resultSetPrototype);
},
/*** Add other table gateways here ***/
'Application\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('users', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
in my controller...
public function indexAction() {
return new ViewModel(array(
'projects' => $this->getProjectTable()->fetchAll(),
'users' => $this->getUserTable()->fetchAll(),
));
}
So, in your shoppingcontroller.php file, as long as your controller class is extending AbstractActionController and you've included...
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
you should be able to return a ViewModel object that contains the data fetched from your separate database tables. Then you can use as you'd like in your view. For example, I loop through $projects and $users in my view to display the contents.