Get Parameter

I have an activation link sent to a new registrant in my yii app, like this,

http://host/index.php/?r=member/activate? .

if in zend framework I can use such


to retrieve the email parameter, what’s the similar functions in yii to get the parameter

and how’s the correct way to call it within the action ?

from what I found in the manual, there’s this CHttpRequest class and a getQuery()

is this correct ?


or there are other func needed to include in that call ?

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

To retrieve a parameter I do: Yii::app()->request->getParam(‘email’);

Even simply


Many widgets (CPagination, CSort) use simply $_GET, I think that this is the standard way.

thanks for all of your answers answers…problem solved

I don’t think a simple $_GET[‘email’] would be appropriate without an isset() verification. Something about error_reporting(E_ALL);.

ini_set('display_errors', 1);


//this could break..

$email = $_GET['email']; 

//this is safe!

$email = isset($_GET['email']) ? $_GET['email'] : "";

//this is perfect (:

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

So would be easier to use Yii method getQuery, that already does this validation

public function getQuery($name,$defaultValue=null)


                return isset($_GET[$name]) ? $_GET[$name] : $defaultValue;


Yes that’s what it’s for. If you have a special url rule that enforces a certain param like $id, you can simply do $_GET[‘id’], otherwise getQuery() will fit better.


I have request where i don’t know the name of the GET param like this :

How i can retrieve "1-gghdgdfgdfgdf" in a Yii way ?

without doing hacks like :


echo $req[''];

Hi. In case you don’t get a more specific answer, check properties and methods of it’s certainly there

oops the id was not detected because of (in config/main.php):


i replaced it by :


and now it works fine.

Is there a way to get all?

the Yii way to get email


How about if I want to get all POST/GET PARAMS using Yii?

This does not work.

$params = Yii::app()->request->getParam();

Simply, I want to get all POST/GET if it is possible.

Wanted result:


"email" => "",

"name" => "name1 name2 "


If you need all the params you can use $_GET and $_POST

or $_REQUEST but note that this one holds all the values of $_GET, $_POST and $_COOKIE