Welcome Guest, Not a member yet? Register   Sign In
Add filters to routing.
#1

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
Reply
#2

do you mean something like this :

$routes->add('feed', function()
{
$rss = new RSSFeeder();
return $rss->feed('general');
});
Reply
#3

No.
It not work to:

$routes->add('users/profile', 'Users::profile', ['as' => 'profile', 'filter' => '123]);
Reply
#4

Can you not do something like...

public filters = [
'users/profile' => ['before' => ['Filter123']],
// ...
];

See https://codeigniter4.github.io/CodeIgnit...ml#filters
Reply
#5

(This post was last modified: 09-23-2019, 04:28 AM by br_salviano.)

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.
Reply
#6

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB