Robin Singh
Robin Singh

Reputation: 1796

How can I use route namespace?

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 "App\Http\Controllers\Admin" 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']);

Upvotes: 0

Views: 1460

Answers (2)

nadim achmad
nadim achmad

Reputation: 96

use like this

$routes->group('admin', ['filter' => 'auth', 'namespace' => 'App\Http\Controllers\Admin'], function($routes)
{
     $routes->get('/', 'AdminController::index');
     $routes->get('channels', 'ChannelController::index');
}

Upvotes: 0

Aashish gaba
Aashish gaba

Reputation: 1776

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

Upvotes: 1

Related Questions