I want to change the link to a view from
recipes/view/slug
to
recipes/slug
therefore I added in routes.php::
$routes->scope('/', function (RouteBuilder $builder): void {
/*
* Here, we are connecting '/' (base path) to a controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, templates/Pages/home.php)...
*/
$builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
/*
* ...and connect the rest of 'Pages' controller's URLs.
*/
$builder->connect('/pages/*', 'Pages::display');
/**************/
/* the route for recipes/view */
$builder->connect( '/recipes/{slug}',
[ 'controller' => 'Recipes', 'action' => 'view', ],
[ '_name' => 'recipe-view',]
);
In the Controller I build the Url with:
Router::url(['_name' => 'recipe-view', 'slug' => $recipe->slug])
When calling the generated URL I get this Error:
Expression
Recipes.slugis missing operator (IS, IS NOT) with
null value.
Can someone help me understanding what I´m doing wrong?