core icon indicating copy to clipboard operation
core copied to clipboard

code reduction with parameters

Open oscarlosan opened this issue 3 years ago • 2 comments

class Greeting {
    public static function hello($params) {
        echo 'hello '.$params['planet'].'!';
    }
}

//it would be interesting to be able to pass parameters. It would reduce my code by 30%. All in the same line:

Flight::route('/', array('Greeting','hello', ['planet' => 'Earth']));

oscarlosan avatar May 18 '21 15:05 oscarlosan

Perhaps you could try overriding the router. See here: https://flightphp.com/learn#overriding

paxperscientiam avatar Dec 01 '21 19:12 paxperscientiam

If your controller methods need static parameters, then you may rethink your code design. The default router is optimized for capturing user-supplied dynamic inputs.

masroore avatar Mar 13 '22 05:03 masroore

If your controller methods need static parameters, then you may rethink your code design. The default router is optimized for capturing user-supplied dynamic inputs.

I agree, I think that this isn't the way to go with the framework moving forward, but appreciate the feedback! Overriding is probably your best bet.

n0nag0n avatar Jan 11 '24 22:01 n0nag0n