问题
Config in global.php
or local.php
not working but works from module.config.php
in laminas API.
So when developer mode is enabled it works with local.php
but as soon as I deploy it doesn't. But when I add the database details in module.config.php
then it works.
public function __invoke($services)
{
$db = 'Db\StatusLib';
$table = 'status';
if ($services->has('config')) {
$config = $services->get('config');
switch (isset($config['statuslib'])) {
case true:
$config = $config['statuslib'];
$db = isset($config['db']) ? $config['db'] : $db;
$table = isset($config['table']) ? $config['table'] : $table;
break;
case false:
default:
break;
}
}
if (! $services->has($db)) {
throw new DomainException(sprintf(
'Unable to create %s due to missing "%s" service',
TableGateway::class,
$db
));
}
return new TableGateway($table, $services->get($db));
}
https://github.com/laminas-api-tools/statuslib-example/blob/master/src/TableGatewayFactory.php#L26
https://github.com/laminas-api-tools/statuslib-example/blob/master/config/module.config.php#L12
return [
'statuslib' => [
// 'array_mapper_path' => 'path/to/PHP/file/returning/array.php',
],
'service_manager' => [
'aliases' => [
Mapper::class => ArrayMapper::class,
// Legacy Zend Framework aliases
],
'factories' => [
ArrayMapper::class => ArrayMapperFactory::class,
TableGatewayMapper::class => TableGatewayMapperFactory::class,
TableGateway::class => TableGatewayFactory::class,
],
],
];
As soon as I move these configs to local.php
or global.php
then it throws this error:
Service with name "StatusLib\TableGateway" could not be created. Reason: Unable to create StatusLib\TableGateway due to missing "Db\StatusLib" service
What am I missing?
UPDATE
And the cache is disabled.
来源:https://stackoverflow.com/questions/61679035/config-in-global-php-or-local-php-not-working-but-works-from-module-config-php-i