# Need Help to understand "Routing" / Cakephp 5

**URL:** <https://discourse.cakephp.org/t/need-help-to-understand-routing-cakephp-5/12280>\
**Category:** Uncategorized\
**Created:** [October 14, 2024, 11:41am UTC](https://discourse.cakephp.org/t/need-help-to-understand-routing-cakephp-5/12280 "2024-10-14T11:41:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [October 14, 2024, 11:41am UTC](https://discourse.cakephp.org/t/need-help-to-understand-routing-cakephp-5/12280/1 "2024-10-14T11:41:49Z")

</div>

I want to change the link to a view from

`recipes/view/slug`

to  
`recipes/slug`

therefore I added in routes.php::

```auto
    $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.slug`is missing operator (IS, IS NOT) with`null` value.`

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

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [October 14, 2024, 2:58pm UTC](https://discourse.cakephp.org/t/need-help-to-understand-routing-cakephp-5/12280/2 "2024-10-14T14:58:34Z")

</div>

Per [Routing - 4.x](https://book.cakephp.org/4/en/development/routing.html#configuring-route-options), what you are missing is `->setPass(['slug'])`.

---

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [October 14, 2024, 4:13pm UTC](https://discourse.cakephp.org/t/need-help-to-understand-routing-cakephp-5/12280/3 "2024-10-14T16:13:44Z")

</div>

> [@Zuluru](#):
>
> [Routing - 4.x](https://book.cakephp.org/4/en/development/routing.html#configuring-route-options)

Thank you very much!
