我知道 POST 方法指向控制器中的add()
作为cakephp3
中的默认值。是否可以自定义并将 POST 方法指向index()
?如下所示:
Router::connect(
'/test',
array(
'controller' => 'Test',
'action' => 'index',
'[method]' => 'POST'
)
);
感谢@ndm为我的问题做出了非常明确的解决方案。
我的问题之一是我有$routes->resources('Test');
,它将禁用@ndm的解决方案。所以首先,我注释掉了$routes->resources('Test');
行.
因为我没有在一个可靠的项目上工作,这是一个用于缩小目的的临时项目,所以下面的代码现在对我来说非常有效。
Router::scope('/', function ($routes) {
$routes->setExtensions(['json']);
// $routes->resources('Test');
$routes->post(
'/test',
['controller' => 'Test', 'action' => 'add']
);
});