Search code examples
phpcodeigniterroutesbackendcodeigniter-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');

What is the difference between get and add? I test them both and it seems like they do the same thing


Solution

  • First off i would like to thank @sauhardnc to set me on the right direction.

    Yes, what @sauhardnc is correct, i tried routing a form with a post method to a route with get method and it gives an error. So if you have a form with a post method, use the post method in your route. Add would also work, but i think the method from your form and your route should be the same.

    This would be your route

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

    or

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

    This would be your form

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