Dzhuneyt
Dzhuneyt

Reputation: 8711

Can't Get GET Query Parameters when 'urlFormat' is Set to 'path'

I have tried echo $_GET['id'], var_dump($_GET), but both don't give the desired results.

After enabling urlFormat in the application's main.php file, I can no longer get the query parameter called 'id'.

The url's are of the format: index.php/controller/action/param (I don't have an htaccess file)

Right now the URL looks like: index.php/article/read/daily_proxy_list

Using var_dump($_GET) returns only:

array
  'daily_proxy_list' => string '' (length=0)

And here's how I create the URL to point to this location:

$this->createUrl('article/read', array('id'=>$key));

My question is, how do I get the query parameter named 'id' (or any other name)?

Upvotes: 0

Views: 3045

Answers (2)

dInGd0nG
dInGd0nG

Reputation: 4114

From yii documentation

Since version 1.1.4, Yii has added support for automatic action parameter binding. That is, a controller action method can define named parameters whose value will be automatically populated from $_GET by Yii.

So in order to get the value $_GET['id'] , you simply add an argument $id to the actionRead(). Yii will automatically populate it with $_GET['id']

public function actionRead($id)
{
    var_dump($id);
}

For more info and examples refer to Yii documentation

Upvotes: 3

Steve Chambers
Steve Chambers

Reputation: 39464

Have you tried using parseUrl with $_SERVER['QUERY_STRING'] or similar?

Upvotes: 0

Related Questions