CodeIgniter Forums
DIFINING A ROUTE - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: DIFINING A ROUTE (/showthread.php?tid=90265)



DIFINING A ROUTE - SubrataJ - 02-27-2024

I would like to know which one is the best practice to define a route in CodeIgniter 4:
PHP Code:
$routes->post('registration', [ApiVendorAuthController::class, 'registerVendor']);
$routes->post('registration''ApiVendorAuthController::registerVendor', ['namespace' => 'App\Controllers\Api\Vendor']); 



RE: DIFINING A ROUTE - InsiteFX - 02-27-2024

CodeIgniter 4 User Guide - URI Routing - Assigning Namespace

I only add the namespace on my Routes that are in a Routes Group.

The first one will prepend the namespace, where the second one only applies it to the method.

The above link will explain it for you.


RE: DIFINING A ROUTE - SubrataJ - 02-27-2024

(02-27-2024, 03:33 AM)InsiteFX Wrote: CodeIgniter 4 User Guide - URI Routing - Assigning Namespace

Thank you for the reply, I want to know which is the best way?


RE: DIFINING A ROUTE - InsiteFX - 02-27-2024

It is up to you, but I use the first one on regular Routes and the second one on my Route Groups.