-
tmtuan
Junior Member
-
Posts: 24
Threads: 8
Joined: Mar 2020
Reputation:
2
Hi, i'm using CI 4.0.4 for my project, i'm working on permission check with routes and filter in it, but it seem to be not woking right. My code look like this:
- In App/Filter i declare an filter alias
- in my Acp module i have 2 routes group like this
- and this is my filter class, i'm also print out and exit the code to test
- the problem was, the router just call the fillter class once, it only go to the filter class if i visit the permission route group. it run ok like this
- and it not working when i'm going to the second route url
does any one have the same problem? Can anyone help me with this please
10-11-2020, 10:41 AM
(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
Arch Book CodeIgniter4 on Apache(pages 92-114)
-
ojmichael
Junior Member
-
Posts: 41
Threads: 0
Joined: Jul 2020
Reputation:
0
10-11-2020, 10:36 PM
(This post was last modified: 10-11-2020, 10:36 PM by ojmichael.)
That seems insane..
What happens if you do something like this?
PHP Code: 'myfilter' => ['before' => ['newblog', 'editBlogs', 'removeBlog']], //etc etc
(10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane..
What happens if you do something like this?
PHP Code: 'myfilter' => ['before' => ['newblog', 'editBlogs', 'removeBlog']], //etc etc
good suggestion , thats another thing i will look at :^)
Arch Book CodeIgniter4 on Apache(pages 92-114)
-
tmtuan
Junior Member
-
Posts: 24
Threads: 8
Joined: Mar 2020
Reputation:
2
(10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane..
What happens if you do something like this?
PHP Code: 'myfilter' => ['before' => ['newblog', 'editBlogs', 'removeBlog']], //etc etc
this way good, and it work perfect, i've done this before i wrote my code like in this post. The reason i dont want to write this way is there're a lot of module that we want to develop in the future and i want to keep all change in module only, and team member can only work in the selected module (folder also) they dont have permission to overwirte the app/config so i'm trying the other way to make it
10-14-2020, 05:49 AM
(This post was last modified: 10-14-2020, 05:53 AM by captain-sensible.)
(10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane..
What happens if you do something like this?
PHP Code: 'myfilter' => ['before' => ['newblog', 'editBlogs', 'removeBlog']], //etc etc
The result was sanity was restored and your rep was increased. Good job there is no -ve rep on this site or mine would have gone down; but i guess we all get those code moments ?
Arch Book CodeIgniter4 on Apache(pages 92-114)
|