# Cake 3.9.2 - Dynamic Routing - The action is not defined in Controller

**URL:** <https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009>\
**Category:** Need Help\
**Created:** [December 19, 2021, 5:28pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009 "2021-12-19T17:28:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![magic77](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@magic77](https://discourse.cakephp.org/u/magic77)\
**Post date:** [December 19, 2021, 5:28pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/1 "2021-12-19T17:28:05Z")

</div>

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

```auto
The action testPage is not defined in LandingpagesController

```

My routes setup:

```auto
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](https://book.cakephp.org/3/en/development/routing.html) didn’t solved my Problem.  
So what i’m doing wrong?

Update: changed setup for DashedRoute to:

```auto
Router::defaultRouteClass(DashedRoute::class);
// ...
$routes->fallbacks(DashedRoute::class);

```

---

<div class="post-metadata">

**Author:** ![ADmad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/admad/32/20_2.png) [@ADmad](https://discourse.cakephp.org/u/ADmad)\
**Post date:** [December 19, 2021, 7:14pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/2 "2021-12-19T19:14:57Z")

</div>

You need to use `DashedRoute::class` instead of `'DashedRoute'` for `Router::defaultRouteClass()` and `$routes->fallbacks('DashedRoute')`.

---

<div class="post-metadata">

**Author:** ![magic77](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@magic77](https://discourse.cakephp.org/u/magic77)\
**Post date:** [December 19, 2021, 7:28pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/3 "2021-12-19T19:28:44Z")

</div>

I tried that, but issue still exists

---

<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:** [December 19, 2021, 10:05pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/4 "2021-12-19T22:05:41Z")

</div>

I haven’t done much with custom routing, but `setPatterns(['action' => '[a-z0-9-]+'])` would seem to be setting the action for it to call, rather than a parameter to pass to the `view` action?

---

<div class="post-metadata">

**Author:** ![magic77](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@magic77](https://discourse.cakephp.org/u/magic77)\
**Post date:** [December 20, 2021, 5:55pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/5 "2021-12-20T17:55:22Z")

</div>

@Zuluru when i put in `view` as pattern then i get the same error

If i use the controller name in url like this

```auto
$routes
        ->connect('/landingpages/:slug',
            ['controller' => 'Landingpages', 'action' => 'view'],
        )
        ->setPatterns(['slug' => '[a-z0-9-]+'])
        ->setPass(['slug']);

```

then view function is called.

But how to get rid of the controller name in the url?

---

<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:** [December 20, 2021, 6:28pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/6 "2021-12-20T18:28:16Z")

</div>

So you just want a URL like `/<slug>`? What if the slug is “search” or “admin”, which you already have other routes defined for?

---

<div class="post-metadata">

**Author:** ![magic77](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@magic77](https://discourse.cakephp.org/u/magic77)\
**Post date:** [December 20, 2021, 6:29pm UTC](https://discourse.cakephp.org/t/cake-3-9-2-dynamic-routing-the-action-is-not-defined-in-controller/10009/7 "2021-12-20T18:29:53Z")

</div>

Yes, i need to get rid of.  
Using this Route setup still works with other Routes

```auto
$routes
        ->connect('/:action',
            ['controller' => 'Landingpages', 'action' => 'view'],
        )
        ->setPatterns(['action' => '[a-z0-9-]+'])
        ->setPass(['action']);

```
