Add filters to routing. |
Currently, Filters only support for a group of routes.
How to add filters to one URI. https://bcit-ci.github.io/CodeIgniter4/i...uting.html Thanks
do you mean something like this :
$routes->add('feed', function() { $rss = new RSSFeeder(); return $rss->feed('general'); });
No.
It not work to: $routes->add('users/profile', 'Users::profile', ['as' => 'profile', 'filter' => '123]);
Can you not do something like...
public filters = [ 'users/profile' => ['before' => ['Filter123']], // ... ]; See https://codeigniter4.github.io/CodeIgnit...ml#filters
How can I apply a filter to specific route?
I'm trying something like this: $routes->get('api/category', 'CategoryApi::read'); $routes->post('api/category', 'CategoryApi::create', ['filter' => 'auth']); But the filter is being applied in both routes.
You're right that it only works for groups at the moment. If you want to specify it for a single, you would currently need to do it in the Filters config file. Adding to a single route is a good idea, and one that could be added after 4.0 final release.
Would you mind making an issue over at Github about this so it gets put on the road map. |
Welcome Guest, Not a member yet? Register Sign In |