【问题标题】:Passing parameters into Fatfree routes将参数传递给 Fatfree 路由
【发布时间】:2023-03-20 09:57:01
【问题描述】:

现在对如何完成将参数传递到 fatfree f3 路由有点困惑。

我的设置如下例所示:

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

我在 tweetInterface 类上的“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 语句。

任何帮助将不胜感激!

【问题讨论】:

    标签: php parameter-passing fat-free-framework


    【解决方案1】:

    参数数组作为第二个参数传递:

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

    参照。 https://fatfreeframework.com/3.6/routing-engine#RoutesandTokens

    【讨论】:

      【解决方案2】:

      这也应该有效:

      $f3->get('PARAMS.currency');

      【讨论】:

      • 确认这也有效,非常感谢您的帮助:)
      猜你喜欢
      • 2019-03-03
      • 2018-08-14
      • 2017-07-31
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      相关资源
      最近更新 更多