Welcome Guest, Not a member yet? Register   Sign In
Filter's dont work
#3

(This post was last modified: 11-29-2020, 11:19 PM by tgix.)

(11-29-2020, 02:18 AM)pippuccio76 Wrote: it works fine  but in some controller i want to filter every method and is too boring write a route with filter for every metods
Why ?
I agree, the routes file can easily become unwieldy and extensive.
Have you looked at the $routes->group() function https://codeigniter4.github.io/userguide...ing-routes which may reduce some typing at least?

Real-world example. In my case I went from this:
PHP Code:
// Routes for handling Companies
$routes->options('companies/(.+)''Options::index');
$routes->get('companies/proctors''Companies::proctors', ['filter' => 'bearer-auth:comp']);
$routes->get('companies/findusers''Companies::find_users_to_link', ['filter' => 'bearer-auth:comp']);
$routes->post('companies/link''Companies::post_link', ['filter' => 'bearer-auth:comp']);
$routes->post('companies/linkmanage''Companies::post_linkmanage', ['filter' => 'bearer-auth:comp']);
$routes->get('companies/(:segment)/employees''Companies::get_employees/$1', ['filter' => 'bearer-auth:comp']);
$routes->delete('companies/(:segment)/employees''Companies::delete_employees/$1', ['filter' => 'bearer-auth:comp']); 

To this:

PHP Code:
$routes->options('companies/(.+)''Options::index');
$routes->group('companies', ['filter' => 'bearer-auth:comp'], function($routes) {
    $routes->get('proctors''Companies::proctors');
    $routes->get('findusers''Companies::find_users_to_link');
    $routes->post('link''Companies::post_link');
    $routes->post('linkmanage''Companies::post_linkmanage');
    $routes->get('(:segment)/employees''Companies::get_employees/$1');
    $routes->delete('(:segment)/employees''Companies::delete_employees/$1');
});
$routes->resource('companies', ['controller' => 'Companies''filter' => 'bearer-auth:comp']); 

A bit more readable I think and also reduces the risk of typos.
Reply


Messages In This Thread
Filter's dont work - by pippuccio76 - 11-29-2020, 02:18 AM
RE: Filter's dont work - by InsiteFX - 11-29-2020, 01:25 PM
RE: Filter's dont work - by pippuccio76 - 11-30-2020, 02:25 AM
RE: Filter's dont work - by tgix - 11-29-2020, 11:12 PM
RE: Filter's dont work - by pippuccio76 - 12-03-2020, 01:28 PM
RE: Filter's dont work - by InsiteFX - 12-01-2020, 01:49 PM
RE: Filter's dont work - by pippuccio76 - 12-02-2020, 04:49 AM
RE: Filter's dont work - by Matleyx - 12-02-2020, 09:06 AM
RE: Filter's dont work - by pippuccio76 - 12-02-2020, 10:03 AM
RE: Filter's dont work - by tgix - 12-03-2020, 01:37 PM
RE: Filter's dont work - by pippuccio76 - 12-05-2020, 01:48 AM
RE: Filter's dont work - by tgix - 12-05-2020, 02:01 AM
RE: Filter's dont work - by pippuccio76 - 12-06-2020, 02:27 AM
RE: Filter's dont work - by tgix - 12-06-2020, 07:14 AM
RE: Filter's dont work - by InsiteFX - 12-06-2020, 07:40 AM
RE: Filter's dont work - by pippuccio76 - 12-06-2020, 10:11 AM
RE: Filter's dont work - by SkyRipper - 12-07-2020, 10:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB