Welcome Guest, Not a member yet? Register   Sign In
Filter Group Codeigniter 4
#1

(This post was last modified: 03-19-2021, 11:45 PM by Rivaldy Saputra Agus.)

Hi everyone, I am new to codeigniter version 4.1.1, I want to ask about Routes Filter Group. I created 1 filter for authentication for the authority of each user that has been specified. then I have a routes group like this:
Code:
$routes->group('/halaman', function($routes){
$routes->get('/beranda', 'Halaman::beranda');
$routes->get('/profil', 'Halaman::profil');
$routes->get('/galeri', 'Halaman::galeri');
$routes->get('/tentang', 'Halaman::tentang');
$routes->get('/FAQ', 'Halaman::FAQ');
$routes->get('/cari', 'Halaman::cari');
});


Then I filter the routes group like this:
Code:
$routes->group('/halaman', ['filter' => 'cekauth'], function($routes){

    $routes->get('/beranda', 'Halaman::beranda');
    $routes->get('/profil', 'Halaman::profil');
    $routes->get('/galeri', 'Halaman::galeri');
    $routes->get('/tentang', 'Halaman::tentang');
    $routes->get('/FAQ', 'Halaman::FAQ');
    $routes->get('/cari', 'Halaman::cari');

});
However, the filter does not work, I have followed all the rules in creating a Filter

But if I apply it like this:

Code:
$routes->get('/halaman/beranda', 'Halaman::beranda', ['filter' => 'cekauth']);
It functions the way I want it. How to solve this? please help.
These are My Filters :


Code:
private $sesi;

    public function before(RequestInterface $request, $arguments = null)
    {
        $this->sesi = session();
        if(!is_null($this->sesi->get('masuk'))){
            if($this->sesi->get('wewenang') === "administrator"){
                return redirect()->to('/beranda/administrator');
            }elseif($this->sesi->get('wewenang') === "developer"){
                return redirect()->to('/beranda/developer');
            }else{
                if($this->sesi->get('wewenang') === "konsumen"){
                    return redirect()->to('/beranda/konsumen');
                }
            }
        }
    }
Reply


Messages In This Thread
Filter Group Codeigniter 4 - by Rivaldy Saputra Agus - 03-19-2021, 11:42 PM
RE: Filter Group Codeigniter 4 - by InsiteFX - 03-20-2021, 03:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB