Hi there,
i need to generate content depending on the route using a Slug and “findBySlug”.
So basically the routes for dynamic content will look like
/[a-z0-9-]+
The Route itself invokes the right controller, but tries to call a function equal the Slug
This /test-page
will throw an Exception with
The action testPage is not defined in LandingpagesController
My routes setup:
Router::defaultRouteClass('DashedRoute');
Router::prefix('admin', function ($routes) {
$routes->extensions(['json']);
$routes->connect('/', ['controller' => 'Orders', 'action' => 'index']);
$routes->fallbacks('DashedRoute');
});
Router::scope('/', function ($routes) {
$routes->connect('/', ['controller' => 'Products', 'action' => 'home']);
$routes->connect('/search', ['controller' => 'Products', 'action' => 'search']);
// many other routes, some static, some dynamic ones
// this will result in action not found
$routes->connect('/:action',
['controller' => 'Landingpages', 'action' => 'view'],
)->setPatterns(['action' => '[a-z0-9-]+'])
->setPass(['action']);
$routes->connect('/*', ['controller' => 'Products', 'action' => 'index']);
$routes->fallbacks(DashedRoute::class);
});
Reading through the Docs Routing - 3.10 didn’t solved my Problem.
So what i’m doing wrong?
Update: changed setup for DashedRoute to:
Router::defaultRouteClass(DashedRoute::class);
// ...
$routes->fallbacks(DashedRoute::class);