CodeIgniter Forums
Get controller's method variables in Filter's before method - 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: Get controller's method variables in Filter's before method (/showthread.php?tid=77184)



Get controller's method variables in Filter's before method - yassine - 07-30-2020

Hi,

I know it is possible to get the variables in the controller's _remap() method though I'd like to have a filter handling a logic at a higher level (if possible).

Here's an example of my code:
PHP Code:
        $routes->get('users/(:num)''User::view/$1', [
            'as' => 'user',
            'filter' => 'permission:user-view',
        ]); 

Is there a way to get the userId I'm passing in the route inside the before method of the permission filter?

Thanks for any help!


RE: Get controller's method variables in Filter's before method - yassine - 07-30-2020

Actually, nevermind, I just found out how to get the params! Smile

For anyone interested, I called the router service, in which there is the params() method.

Like so:

PHP Code:
        $router Services::router();
        echo var_dump($router->params());
        
// array(1) { [0]=> string(1) "1" }