$routes->get 和 $routes->add 在 codeigniter 4 中有什么区别?

What is the difference between $routes->get and $routes->add in codeigniter 4?

$routes->get('login', 'C_auth::display_login');
$routes->add('login', 'C_auth::display_login');

getadd 有什么区别?我测试了他们两个,看起来他们做同样的事情

首先,我要感谢@sauhardnc 为我指明了正确的方向。

是的,@sauhardnc 是正确的,我尝试将使用 post 方法的表单路由到使用 get 方法的路由,但出现错误。因此,如果您有一个带有 post 方法的表单,请在您的路由中使用 post 方法。 Add 也可以,但我认为您的表单和路线中的方法应该相同。

这就是你的路线

$routes->post('register-user','C_auth::authenticate_registration');

$routes->add('register-user','C_auth::authenticate_registration');

这就是您的表单

<form action = '<?php echo route_to('register-user') ?>' method="post" accept-charset="utf-8">