I’m trying to add new controller and routes for it in laminas, I have some stracture of module like this: https://i.stack.imgur.com/tOts6.png
ConfigProvider contains:
<?php
declare(strict_types=1);
namespace RoleApi;
use Laminas\Router\Http\Segment;
use Laminas\ServiceManager\Factory\InvokableFactory;
use RoleApi\Application\Controller\ResourceController;
/**
* The configuration provider for the RoleApi module
*
* @see https://docs.laminas.dev/laminas-component-installer/
*/
class ConfigProvider
{
/**
* Returns the configuration array
*
* To add a bit of a structure, each section is defined in a separate
* method which returns an array with its configuration.
*/
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'templates' => $this->getTemplates(),
'controllers' => $this->getControllers(),
'router' => $this->getRouter(),
];
}
/**
* Returns the container dependencies
*/
public function getDependencies(): array
{
return [
'invokables' => [
],
'factories' => [
],
];
}
/**
* Returns the templates configuration
*/
public function getTemplates(): array
{
return [
'paths' => [
],
];
}
public function getControllers(): array
{
return [
'factories' => [
ResourceController::class => InvokableFactory::class,
],
];
}
public function getRouter(): array
{
return [
'routes' => [
'resource' => [
'type' => Segment::class,
'options' => [
'route' => '/api/resource[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => ResourceController::class,
'action' => 'index',
],
],
],
]
];
}
}
RoleApi\ConfigProvider::class is injected in config.php
But there’s a 404 on all /api/resource/*
Only routes that are described in routes.php are working:
<?php
declare(strict_types=1);
use Mezzio\Application;
use Mezzio\MiddlewareFactory;
use Psr\Container\ContainerInterface;
return static function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {
$app->get('/', App\Handler\HomePageHandler::class, 'home');
$app->get('/ping', App\Handler\PingHandler::class, 'ping');
};
Any clues what I’m doing wrong?