【发布时间】:2019-09-15 15:36:16
【问题描述】:
我已经定义了我的路由和控制器如下
$router->group(['prefix' => 'api/v1'], function ($router) {
$router->group(
['middleware' => 'auth'], function() use ($router) {
$router->get('/order/get-order-status/{order_id}[/{account_id}]'
, [
'uses' => 'Api\V1\OrderController@getOrderStatus'
, 'as' => 'getOrderStatus'
]
);
});
});
下面是函数定义
public function getOrderStatus($orderId, $accountId = false)
{
// my code goes here
}
这里的问题是,每当我从路由中跳过可选的account_id,然后将传递的order_id 分配给函数的第二个参数,即accountId。如果我通过两个参数,那么一切都按预期工作。我只是很困惑我的配置是否有问题或Lumen 本身与可选路由参数有问题?
假设我触发了http://localhost/lumen/api/v1/order/get-order-status/ORD1234,然后ORD1234 被分配给accountId,而“0”被分配给orderId
【问题讨论】:
-
你的 url 和你的路由不一样。在您的路线上,您说它必须是这样的:localhost/lumen/api/v1/order/get-order-status/ORD1234[/1]。但是您触发的路线是localhost/lumen/api/v1/order/get-order-status/ORD1234
标签: php laravel laravel-routing lumen laravel-route