sasori
(Nemo Md5)
November 9, 2010, 10:16am
1
I have an activation link sent to a new registrant in my yii app, like this,
http://host/index.php/?r=member/activate?email=emailaddress@test.com .
if in zend framework I can use such
$this->getRequest()->getQuery('email');
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 ?
CHttpRequest::getQuery('email');
or there are other func needed to include in that call ?
rudenich
(Rudenich)
November 9, 2010, 10:29am
2
$email = Yii::app()->request->getQuery('email');
To retrieve a parameter I do: Yii::app()->request->getParam(‘email’);
zaccaria
(Matteo Falsitta)
November 9, 2010, 10:39am
4
Even simply
$_GET['email']
Many widgets (CPagination, CSort) use simply $_GET, I think that this is the standard way.
sasori
(Nemo Md5)
November 9, 2010, 10:45am
5
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);
error_reporting(E_ALL);
//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;
}
Y11
(Y!!)
November 10, 2010, 11:45pm
7
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.
saegeek
(Abdallah)
April 9, 2012, 9:13am
8
Hi,
I have request where i don’t know the name of the GET param like this :
http://127.0.0.1/products/index/1-gghdgdfgdfgdf
How i can retrieve "1-gghdgdfgdfgdf" in a Yii way ?
without doing hacks like :
$req=array_flip($_GET);
echo $req[''];
abennouna
(Abennouna)
April 9, 2012, 9:22am
9
Hi. In case you don’t get a more specific answer, check properties and methods of http://www.yiiframework.com/doc/api/1.1/CHttpRequest it’s certainly there
saegeek
(Abdallah)
April 9, 2012, 10:49am
10
oops the id was not detected because of (in config/main.php):
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
i replaced it by :
'<controller:\w+>/<action:\w+>/<id:\d+\-\w+>'=>'<controller>/<action>',
and now it works fine.
Is there a way to get all?
the Yii way to get email
Yii::app()->request->getParam('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:
array(
"email" => "user@example.com ",
"name" => "name1 name2 "
)
mdomba
(Maurizio Domba Cerin)
November 13, 2012, 8:50am
12
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