![]() |
route filters does not work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: route filters does not work (/showthread.php?tid=77726) |
route filters does not work - tmtuan - 10-11-2020 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 RE: route filters does not work - captain-sensible - 10-11-2020 this is my Filters.php at app/Config Code: use CodeIgniter\Config\BaseConfig; 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 RE: route filters does not work - ojmichael - 10-11-2020 That seems insane.. What happens if you do something like this? PHP Code: 'myfilter' => ['before' => ['newblog', 'editBlogs', 'removeBlog']], //etc etc RE: route filters does not work - captain-sensible - 10-12-2020 (10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane..good suggestion , thats another thing i will look at :^) RE: route filters does not work - tmtuan - 10-12-2020 (10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane.. 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 RE: route filters does not work - captain-sensible - 10-14-2020 (10-11-2020, 10:36 PM)ojmichael Wrote: That seems insane.. 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 ? |