【发布时间】:2017-11-28 22:39:17
【问题描述】:
所以,我有一段代码,用于我的路线,如下所示:
Router::scope('/v1', function (RouteBuilder $routes) {
$routes->resources( 'Files', [
'map' => [
'index' => ['action' => 'index', 'method' => 'GET', 'path' => ''],
'create' => ['action' => 'add', 'method' => 'POST', 'path' => ''],
'view' => ['action' => 'view', 'method' => 'GET', 'path' => ':id'],
'update' => ['action' => 'edit', 'method' => ['PUT', 'PATCH'], 'path' => ':id'],
'delete' => ['action' => 'delete', 'method' => 'DELETE', 'path' => ':name'],
]
]);
});
我有一个类似的网址:http://192.168.1.197/v1/files/13625a1ddedcbc2011-40115501.jpg
我希望13625a1ddedcbc2011-40115501.jpg 成为您在上面的'delete' => ['action' => 'delete', 'method' => 'DELETE', 'path' => ':name'] 路由中看到的:name 参数,但是,无论我做什么(我什至在这里尝试了正则表达式)我都会收到错误:
函数 App\Controller\FilesController::delete() 的参数太少,传入 0
我可能已经阅读了它的文档一千遍:https://book.cakephp.org/3.0/en/development/routing.html,但我不知道如何。
我看了一下这个答案,关于如何使用它有点含糊,这意味着我将所有路线更改为:How to give string in the url in RESTful api in Cakephp? 我不想这样做。
如何获取这个参数?
【问题讨论】:
标签: php cakephp url-routing cakephp-3.0