How to get Yii parameters directly from the querystring (URL)
33,126
Solution 1
On somthing like -
$this->createUrl('blah/blahx',array('id'=>2));
You can get your parameter using -
$x = CHttpRequest::getParam('id'); //outputs x=2
OR $x = Yii::app()->getRequest()->getQuery('id'); //x=2 again
Solution 2
you can try getParam method
$id = Yii::app()->request->getParam('id');
Solution 3
You should read this :
- http://www.yiiframework.com/doc/guide/1.1/en/topics.url
- http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#action-parameter-binding
About your problem, you should simply create a corresponding url rule, e.g. :
'events/<param1>/<param2>'=>'events/view',
And then in your controller :
public function actionView($param1, $param2)
{
// you can now use $param1 and $param2
}
Comments
-
Zabs almost 2 years
I am using the latest version of Yii and trying to basically collate the URL parameters.
For instance if my URL was as follows:
site.com/events/199/111
What is the function to grab the first parameter e.g '199' and similarly again to say grab the 2nd parameter e.g '111'.
I remember CodeIgniter has
$this->url->segment(1)
, I basically need the same functionality to Yii :) -
Zabs over 10 yearsI will do have to wait a few more mins :)
-
iltaf khalid almost 10 yearsI had the follwing URL i.e. localhost/FedSeed/reports/multi/1 and I used CHttpRequest::getParam('id'); to access the last 1 digit :)