CodeIgniter Forums
How To Add Filter On Specified HTTP Method and Controller in Routes.php? - 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: How To Add Filter On Specified HTTP Method and Controller in Routes.php? (/showthread.php?tid=78748)



How To Add Filter On Specified HTTP Method and Controller in Routes.php? - simonickalexs - 03-06-2021

What I've tried to achieve is add filter on specified http method and controller. Like:

PHP Code:
$rotues->get('/''Home::index', ['filter' => 'user']);
$rotues->post('/''Home::new', ['filter' => 'admin']); 

But when I call the HTTP GET method, the filter is always use admin while I specified that to use user. How could I achieve this? Thanks.


RE: How To Add Filter On Specified HTTP Method and Controller in Routes.php? - iRedds - 03-06-2021

I cannot reproduce.
Have you registered the user filter with the admin class?


RE: How To Add Filter On Specified HTTP Method and Controller in Routes.php? - IvanBell - 03-06-2021

Shouldn't it be $routes instead of $rotues?


RE: How To Add Filter On Specified HTTP Method and Controller in Routes.php? - simonickalexs - 03-07-2021

(03-06-2021, 08:53 AM)IvanBell Wrote: Shouldn't it be $routes instead of $rotues?

Ah I have typo inserted in the post, but in my code is $routes  Thank you

(03-06-2021, 08:35 AM)iRedds Wrote: I cannot reproduce.
Have you registered the user filter with the admin class?

Yes, and I'm using the 4.0.4 version, and I've found out they fixed it in the latest version https://github.com/codeigniter4/CodeIgniter4/issues/3733. But the problem is, if I'm upgrade it, I will encounter with this issue "CI4 Generate Empty String On Query Binding Value On "FALSE" value (codeigniter.com)". This is a big dilemma and chicken and egg for me since I have no choice to upgrade and rewrite the whole code, my God.


RE: How To Add Filter On Specified HTTP Method and Controller in Routes.php? - iRedds - 03-08-2021

CI 4.1.1 php 7.3 MySQL 5.5 & MySQL 8  - Works perfect.

What am I doing wrong?

You can use DB events in which to convert bool 2 int