0

我目前正在学习如何将rest api用于移动开发,我只想知道是否有一种方法可以在URL中接受多个变量?

例如:

$app->get('/chara/arena/:id', 'getArea');
//now this code above can accept only 1 prameter now how do i make it to accept 2 parameters?

喜欢:

/chara/arena?idA=102&idB=123

顺便说一句,我正在使用 SLIM 框架。

4

2 回答 2

1

试试这个代码:

$idA = $app->request()->get('idA');
$idB = $app->request()->get('idB');
于 2013-04-25T04:20:11.600 回答
1

我设法以某种方式创建了一个解决方案:我没有传递 1 个字符的 id,而是同时传递了它们

因此,如果我想传递 id 的 1 和 2,我将传递它们 /chara/battle/1:2 并像数组一样使用爆炸。

 $app->get('/chara/battle/:mid', 'setArena');

 function setArena($raw_ids){
      $ids = explode(':', $raw_ids);
        $chara_a_id = $ids[0];
        $chara_b_id = $ids[1];
 }

我不知道这可以这么简单。

于 2013-04-25T08:46:44.370 回答