CakePHP 3: Missing route error for route that exists

后端 未结 2 798
离开以前
离开以前 2020-12-16 19:28

CakePHP 3.0

I\'m getting a \"Missing Route\" error for a route that exists.

Here are my routes:

#my admin routes...
Router::prefix(\'admin\'         


        
相关标签:
2条回答
  • 2020-12-16 19:45

    Take a closer look at the stacktrace, the error dosn't occour in the dispatching process, which you seem to think, it is being triggered in your view template, where you are probably trying to create a link to the add action, and reverse-routing cannot find a matching route, hence the error.

    The solution should be obvious, connect the necessary routes, being it explicit ones like

    $routes->connect('/screens/add', ['controller' => 'Screens', 'action' => 'add']);
    

    catch-all ones

    $routes->connect('/screens/:action', ['controller' => 'Screens']);
    

    or simply the fallback ones that catch everything

    $routes->fallbacks('InflectedRoute');
    
    0 讨论(0)
  • 2020-12-16 19:52

    This work for me in case of use prefix admin :-

    Router::prefix('admin', function ($routes) {
        // Because you are in the admin scope,
        // you do not need to include the /admin prefix
        // or the admin route element.
        $routes->connect('/', ['controller' => 'Users', 'action' => 'index']);
        $routes->extensions(['json', 'xml']);
        // All routes here will be prefixed with `/admin`
        $routes->connect('/admin', ['controller' => 'Order', 'action' => 'index']);
        // And have the prefix => admin route element added.
        $routes->fallbacks(DashedRoute::class);
    }); 
    
    0 讨论(0)
提交回复
热议问题