Welcome Guest, Not a member yet? Register   Sign In
Filters just made my head explode?
#1

(This post was last modified: 09-07-2020, 02:27 AM by blaasvaer.)

OK, here's another thing I don't get in CI4 ... Filters!

HOW do I protect AdminControllers using Filters? I want to be able to create AdminControllers that are proctected by 'some' authorization process ... now, I've read the doc (many times), and I simply cannot wrap my head around HOW to APPLY them to my SPECIFIC controllers.

I've created a filter (Authorize.php) just for testing purposes that I placed in the App\Filters folder.
I'm now STARING at the App\Config\Filters.php file where I've added this line (yes, simply monkeying from the docs):

Code:
'authorize' => \App\Filters\Authorize::class,

under '$aliases'.

Now, HOW do I apply it to protect all AdminControllers? I simply cannot figure this out from the docs ... yes, I AM stupid, obviously.

If I try to add it to the 'before' array, then it gets called on ALL controllers, sending me into an infinite redirection loop ... HOW do I APPLY it to ONLY AdminControllers? Is this ROUTE based or what?

Please, make the docs CLEAR on HOW to make the filter work in SPECIFIC areas of the app ... this simply wont cut it:

Configuring Filters

Once you’ve created your filters, you need to configure when they get run. This is done in app/Config/Filters.php. This file contains four properties that allow you to configure exactly when the filters run.
Don't know what's wrong with this editor but it seems to bloat replies with white space when previwing posts in edit mode ... yeah, this thing is broken to.
Reply
#2

To add a filter to a route you do it like so.

PHP Code:
<?php

namespace Insitefx\Admin\Config;

/**
 * Insitefx/Name: routes file.
 */


/** @var TYPE_NAME $routes */
$routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes)
{
    $routes->get('dashboard''Dashboard::index', ['filter' => 'login']);
}); 

See the filter in the dashboard route? If they are not logged in it will load the login view.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB