将参数传递给 Fatfree 路由
Passing parameters into Fatfree routes
现在对如何完成将参数传递到 fatfree f3 路由有点困惑。
我的设置如下例所示:
$f3->route('GET /tweetRate/@currency','Tweets\tweetInterface::tweet');
我在 tweetInterface class 上的 "tweet" 方法能够接受一个参数,但我永远无法真正确认它是否被传入。
static function tweet($currency) {
echo 'Inside Route';
echo $currency;
}
我已经确认我能够到达这条路线,因为我的第一个回显 "Inside Route" 能够被打印出来,但是在回显参数时没有显示 $currency。以下是我如何调用此路由的示例:
php routes.php "/tweetRate/USD" > /Users/johndoe/Desktop/test.log
在 "test.log" 内部,我能够看到我的第一个 echo 语句,如上所述。
如有任何帮助,我们将不胜感激!
参数数组作为第二个参数传递:
static function tweet(\Base $f3, array $params) {
echo 'Inside Route';
echo $params['currency'];
}
比照。 https://fatfreeframework.com/3.6/routing-engine#RoutesandTokens
这也应该有效:
$f3->get('PARAMS.currency');
现在对如何完成将参数传递到 fatfree f3 路由有点困惑。
我的设置如下例所示:
$f3->route('GET /tweetRate/@currency','Tweets\tweetInterface::tweet');
我在 tweetInterface class 上的 "tweet" 方法能够接受一个参数,但我永远无法真正确认它是否被传入。
static function tweet($currency) {
echo 'Inside Route';
echo $currency;
}
我已经确认我能够到达这条路线,因为我的第一个回显 "Inside Route" 能够被打印出来,但是在回显参数时没有显示 $currency。以下是我如何调用此路由的示例:
php routes.php "/tweetRate/USD" > /Users/johndoe/Desktop/test.log
在 "test.log" 内部,我能够看到我的第一个 echo 语句,如上所述。
如有任何帮助,我们将不胜感激!
参数数组作为第二个参数传递:
static function tweet(\Base $f3, array $params) {
echo 'Inside Route';
echo $params['currency'];
}
比照。 https://fatfreeframework.com/3.6/routing-engine#RoutesandTokens
这也应该有效:
$f3->get('PARAMS.currency');