The error code is Laminas\ServiceManager\Exception\ServiceNotFoundException File: D:\Projects\validation\vendor\laminas\laminas-servicemanager\src\ServiceManager.php:586
The error message is Unable to resolve service "Laminas\Db\Adapter\AdapterInterface" to a factory; are you certain you provided it during configuration?
Module.php file:
<?php
namespace Album;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\TableGateway\TableGateway;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig()
{
return [
'factories' => [
Model\AlbumTable::class => function($container) {
$tableGateway = $container->get(Model\AlbumTableGateway::class);
return new Model\AlbumTable($tableGateway);
},
Model\AlbumTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\AlbumController::class => function($container) {
return new Controller\AlbumController(
$container->get(Model\AlbumTable::class)
);
},
],
];
}
}
module.config.php file:
<?php
namespace Album;
use Laminas\Router\Http\Segment;
return [
'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];
modules.config.php file:
<?php
/**
* List of enabled modules for this application.
*
* This should be an array of module namespaces used in the application.
*/
return [
'Laminas\Router',
'Laminas\Validator',
'Application',
'Album',
];
The problem seems to be that the tutorial uses Laminas\Db service that isnt there anymore in the modules.config.php file, the tutorial shows a modules.config.php file that is different than mine, I tried adding 'Laminas\Db' there but this just results in a different error.
The Laminas\Db\Adapter\AdapterInterface-Service is initiated by simply adding your specific Db-configuration into your in
config/autoload/global.phpand/orconfig/autoload/local.phpwith the key db.Example for SQLITE:
See: Tutorial part on DB
For examples on how to configure your DB for other adapters like MySql see the docs on DB-Adapters