0

i am currenty learning how to use rest api for mobile dev't, i just want to know is there a method for accepting multiple variables in the URL?

for example:

$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?

like:

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

im using SLIM framework btw.

2 Answers 2

1

Try this code:

$idA = $app->request()->get('idA');
$idB = $app->request()->get('idB');
Sign up to request clarification or add additional context in comments.

Comments

1

i managed to create a solution somehow: instead of passing the id of 1 character i pass them at the same time

so if i wanted to pass the id's 1 and 2 i will pass them /chara/battle/1:2 and use explode like an array.

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

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

i didnt know this can be so simple.

2 Comments

Or: list($chara_a_id, $chara_b_id) = explode(':', $raw_ids);
i didnt know such function exist, kudos yo you @Madbreaks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.