Search code examples
phpparameter-passingfat-free-framework

Passing parameters into Fatfree routes


Bit confused on how to accomplish passing a parameter into a fatfree f3 route right now.

My setup is shown in an example below:

$f3->route('GET /tweetRate/@currency','Tweets\tweetInterface::tweet');

My "tweet" method on the tweetInterface class is able to accept a parameter, but I am never able to actually confirm that it is being passed in.

static function tweet($currency) {

   echo 'Inside Route';

   echo $currency;
}

I have confirmed that I am able to hit this route because my first echo of "Inside Route" is able to be printed, but nothing ever shows up for $currency when echoing the paramter. Below is a sample of how I am calling this route:

php routes.php "/tweetRate/USD" > /Users/johndoe/Desktop/test.log

Inside of "test.log" I am able to see my first echo statement as mentioned above.

Any help would be greatly appreciated!


Solution

  • The array of parameters is passed as the 2nd argument:

    static function tweet(\Base $f3, array $params) {
      echo 'Inside Route';
      echo $params['currency'];
    }
    

    Cf. https://fatfreeframework.com/3.6/routing-engine#RoutesandTokens