0

Let's say my url looks like this now - .../users/promote/21. I tried getting the id by several ways but it was unlucky. I figured out that I can use $_SERVER['REQUEST_URI'] and just split it by '/' and take the last element but I think that there are better ways to do this. So my question is how can i get the number 21 so I can use it in the users controller?

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

you should have users controller

<a href="http://www.example.com/users/promote?userId=21"></a>

set the url like this example and

public function promote(){
$userId= $_GET ["userId"];
var_dump($userId);
}

you will get the value 21

Gireesh T
  • 57
  • 1
  • 9
  • That code doesnt work. Not even a little bit, if you are not using a framework. And recommending a newbie to use a framework would be probably quite harmful. Have a downvote. – tereško Aug 29 '16 at 17:47
  • This won't work, simply because whenever i hit the button it will redirect to promote?userId=21 and an error will occur saying that function 'promote?userId=21' doesn't exist in Users Controller – Ivaylo Barakov Aug 30 '16 at 08:56