CodeIgniter Forums
question about routes and filter - 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: question about routes and filter (/showthread.php?tid=80401)



question about routes and filter - Secux - 10-27-2021

is it possible to take a dynamic value from (:num) and use it in a filter?

routes:
PHP Code:
$routes->group('(:num)', ['subdomain' => 'test1''filter' => 'filtertest:$1'], function ($routes) { 

as $1 is (:num)

filter:
PHP Code:
public function before(RequestInterface $request$arguments null)
    {
        if(
$arguments['0']){ 

reurn: Array ( [0] => $1 )


and one more question is it possible to put ['get', 'post'] in a group? ?


RE: question about routes and filter - includebeer - 10-31-2021

For your second question, yes you should be able to set a route for get and post. Something like this:
PHP Code:
$routes->group('admin', function ($routes) {
    $routes->add('foo''Admin\Foo::index'); // any verb (GET, POST, PUT, DELETE…)
    $routes->get('bar''Admin\Bar::index'); // GET only
    $routes->post('biz''Admin\Biz::index'); // POST only
    $routes->match(['get''post'], 'baz''Admin\Baz::index'); // GET or POST only
}); 

See :
Grouping: http://codeigniter.com/user_guide/incoming/routing.html#grouping-routes
HTTP verbs: http://codeigniter.com/user_guide/incoming/routing.html#using-http-verbs-in-routes