Welcome Guest, Not a member yet? Register   Sign In
Grouping routes with multiple filters
#1

(This post was last modified: 01-13-2024, 06:46 AM by adimancifi.)

Hi all. I use Codeigniter v4.4.4 PHP 8.3.1. and i have problem with grouping routes multiple filters.

PHP Code:
$routes->group('toko', [
        'namespace' => 'Admin\Controllers',
        'filter' => 'sudah_login'
    ],
    function($routes) {
        
        $routes
->add('daftar-item''TokoController::daftarItem', [ 
            'filter' => 'Roles:read' 
        ]);
        
        $routes
->add('tambah-item''TokoController::tambahItem', [ 
            'filter' => ['sudah_login''Roles:write'
        ]);
}); 



Filter 'filter' => 'sudah_login' from parent is not work for child routes. I must put again that's filter to child routes to make work it.
is it like that or is this a bug?


Thank's.
Reply
#2

(This post was last modified: 01-13-2024, 05:30 AM by InsiteFX.)

Your group array is missing a , comma after the namespace.

PHP Code:
// Missing comma
$routes->group('toko', [
        'namespace' => 'Admin\Controllers' <-- no comma!
        'filter' => 'sudah_login'
    ],


// Should be:
$routes->group('toko', [
        'namespace' => 'Admin\Controllers',
        'filter' => 'sudah_login'
    ], 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-13-2024, 06:51 AM by adimancifi.)

already edited. just in this post I forgot the comma.
So, even if i put the comma still not work.
Reply
#4

Just found this:

Route group filter
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

See https://github.com/codeigniter4/CodeIgniter4/pull/8033
https://github.com/codeigniter4/CodeIgni...ssues/7963

We will fix this as a bug, but the impact is big. So it will be fixed in 4.5.0.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB