Welcome Guest, Not a member yet? Register   Sign In
route filters does not work
#2

(This post was last modified: 10-11-2020, 10:47 AM by captain-sensible.)

this is my Filters.php at app/Config

Code:
use CodeIgniter\Config\BaseConfig;

class Filters extends BaseConfig
{
    // Makes reading things below nicer,
    // and simpler to change out script that's used.
    public $aliases = [
        'csrf'     => \CodeIgniter\Filters\CSRF::class,
        'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
        'honeypot' => \CodeIgniter\Filters\Honeypot::class,
        'myfilter'=> \App\Filters\MyFilter::class,
        'myfilter2'=> \App\Filters\MyFilter2::class,
        'myfilter3'=> \App\Filters\MyFilter3::class,
        'myfilter4'=> \App\Filters\MyFilter4::class,
        'myfilter5'=> \App\Filters\MyFilter5::class,
        'myfilter6'=> \App\Filters\MyFilter6::class,
        'myfilter7'=> \App\Filters\MyFilter7::class,
        'myfilter8'=> \App\Filters\MyFilter8::class,
        'myfilter9'=> \App\Filters\MyFilter9::class
        
        
        
        
        
    ];

    // Always applied before every request i removed // that was in front of honeypot and csrf below
    public $globals = [
        'before' => [
            'honeypot',
             'csrf',
        ],
        'after'  => [
            'toolbar',
            //'honeypot'
        ],
    ];

    // Works on all of a particular HTTP method
    // (GET, POST, etc) as BEFORE filters only
    //     like: 'post' => ['CSRF', 'throttle'],
    public $methods = [];

    // List filter aliases and any before/after uri patterns
    // that they should run on, like:
    //    'isLoggedIn' => ['before' => ['account/*', 'profiles/*']],
    public $filters = [
    
    
    'myfilter' => ['before' => ['newblog']], //newblog is a  route
    'myfilter2' => ['before' => ['editBlogs']],//editBlogs is a route
    'myfilter3' => ['before' => ['removeBlog']], //etc etc
    'myfilter4' => ['before' => ['addPortfolio']],
    'myfilter5' => ['before' => ['delPortfolio']],
    'myfilter6' => ['before' => ['portfolioForm']],
    'myfilter7' => ['before' => ['delPortfolioForm']],
    'myfilter8' => ['before' => ['form4']],
    'myfilter9' => ['before' => ['admin']]
    
    
    
    
    
    ];
}

maybe i'm missing something but i found that to work you need a separate filter class for every defined route


this is an extract of Routes.php so you can match it to above:

Code:
$routes->get('delPortfolio','Portfolio::delPortfolio');


you will see myfilter5.php matches the above route //myfilter > myfilter9 yeah no imagination i have

so the get request /delPortfolio calls the class method delPortfolio of class Portfolio .

what i'm checking on this is that admin is logged in in order to access what the method does
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply


Messages In This Thread
route filters does not work - by tmtuan - 10-11-2020, 04:36 AM
RE: route filters does not work - by captain-sensible - 10-11-2020, 10:41 AM
RE: route filters does not work - by ojmichael - 10-11-2020, 10:36 PM
RE: route filters does not work - by tmtuan - 10-12-2020, 07:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB