I am creating routes in codeigniter-4 and I want to know if I can use namespace for some routes like with laravel given below:
Laravel namespace Code
Route::namespace('Admin')->group(function () { // Controllers Within The "AppHttpControllersAdmin" Namespace });
Can I implement something similar in codeigniter-4 ?
My Codeigniter code
$routes->get('/admin', 'AdminController::index', ['filter' => 'auth']); $routes->get('/admin/channels', 'ChannelController::index', ['filter' => 'auth']);
Advertisement
Answer
Yes you can.
$routes->group('api', ['namespace' => 'add your namespace here'], function($routes) { $routes->get('/admin', 'AdminController::index', ['filter' => 'auth']); }
https://codeigniter.com/user_guide/incoming/routing.html#assigning-namespace