Hi,
I have managed to deal with this as described in both treads above, but to summarize:
Add the config parameter to your CLI command, in my case it looks like this:
/vendor/bin/laminas --container <<path to config>><<config-file>>.php <<command>>
and in that config file I am pointing to the URL Helper Factory, created as described in the first link above.
https://discourse.laminas.dev/t/onbootstrap-not-called-for-cli-commands/2447
In my case it looks like this:
$config = require <<path>>. 'application.config.php';
$extendedConfig = [
'view_helpers' => [
'factories' => [
\Laminas\View\Helper\Url::class => \Application\View\Helper\UrlFactory::class,
]
]
];
$container = new ServiceManager();
(new ServiceManagerConfig())->configureServiceManager($container);
$container->setService('ApplicationConfig', $config);
/** @var \Laminas\ModuleManager\ModuleManager $moduleManager */
$moduleManager = $container->get('ModuleManager');
$events = $moduleManager->getEventManager();
$events->attach(\Laminas\ModuleManager\ModuleEvent::EVENT_MERGE_CONFIG, function (\Laminas\ModuleManager\ModuleEvent $e) use ($extendedConfig) {
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
$config = ArrayUtils::merge($config, $extendedConfig);
// Pass the changed configuration back to the listener:
$configListener->setMergedConfig($config);
});
$moduleManager->loadModules();
Don’t forget to “deal” with the config cache if you have such.