0

I have an example link here:

http://mydomain.com/myapp1/index.php/image/index/album/check+picture/id/1

Now I'm trying to retrieve the "1" at the very end of the url.

So far, I've tried the following code:

 $id = $_GET['id'];

But it is not working. I was used to the url having the index.php?id=1 Syntax but I'm not entirely sure how to get this one working.

UPDATE

Before accepting an answer, I wanted to add this script I used to get the entire URL of the current page:

 $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
    $host     = $_SERVER['HTTP_HOST'];
    $script   = $_SERVER['SCRIPT_NAME'];
    $params   = $_SERVER['QUERY_STRING'];
    $currentUrl = $protocol . '://' . $host . $script . '?' . $params;

    echo $currentUrl;

When it echoes, it only prints out:

http://www.mydomain.com/myapp1/index.php?

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
remedy.
  • 2,032
  • 3
  • 25
  • 48

4 Answers4

2

Just do this :

echo basename($_SERVER['REQUEST_URI']);
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
0

Something like this should work for you:

$id = substr($url, strrpos( $url, '/' )+1);
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
-1

Get YII Documentation...

$id = Yii::app()->request->getQuery('id')

Or

$id = Yii::app()->getRequest()->getQuery('id');

Possible duplicate

http://stackoverflow.com/questions/2760869/yii-framework-controller-action-url-parameters
Rohit Awasthi
  • 686
  • 3
  • 12
-2

try this....

$url = "http://mydomain.com/myapp1/index.php/image/index/album/check+picture/id/1";

$value = substr(strrchr(rtrim($url, '/'), '/'), 1);

Ref

In Yii Framework you can get value like this...

$id = Yii::app()->getRequest()->getQuery('id');

OR

$id = Yii::app()->request->getParam('id');
Community
  • 1
  • 1
Zeeshan
  • 1,659
  • 13
  • 17