首页 > 解决方案 > Cakephp 触发错误路由

问题描述

我的路由有问题。我有一个用 Cakephp 3.9 编码的 API,当我调用它时,它会调用我另一个路由。

我想/api/order/customer-quotation通过 POST 调用路由,但是调用了/api/order/:idGET 路由...

这是我的代码的捕获:

Router::plugin('Api', ['path' => '/api'], function ($routes) {
    $routes->registerMiddleware(
        'api-firewall',
        new \Api\Middleware\ApiFirewallMiddleware()
    );
    $routes->applyMiddleware('api-firewall');

    $routes->scope('/order', ['controller' => 'Order'], function($routes) {
        $routes
            ->connect(
                '/customer-quotation',
                ['action' => 'createOrder'],
                ['_name' => 'create_order']
            )
            ->setMethods(['POST']);

        $routes
            ->connect(
                '/:id',
                ['action' => 'getOrderDetails'],
                ['_name' => 'order_details']
            )
            ->setMethods(['GET']);
    });

我无法理解

谢谢

标签: cakephpurl-routingcakephp-3.x

解决方案


推荐阅读