Need Help to understand "Routing" / Cakephp 5

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) withnull value.

Can someone help me understanding what I´m doing wrong?

Per Routing - 4.x, what you are missing is ->setPass(['slug']).

1 Like

Thank you very much!