user2641778
user2641778

Reputation: 13

How to get query string values in YII without PATH format?

I am having following url,

www.example.com/index.php?r=recommend/create&id=184?
title=Ruins%20of%20Mahabalipuram
&url=http://localhost/index.php/mediadetail/index/184

I need to get title and url which are query string parameters.

Has anyone worked on getting values in query string in Yii?

Upvotes: 1

Views: 5895

Answers (3)

ippi
ippi

Reputation: 10167

There is also the getParam() method in CHttpRequest.

Yii::app()->request->getParam('title')

I've found it a valuable shortcut, since it checks both $_POST and $_GET and gives priority to $_GET, so you can use it to override post variables in the address URL. It also performs null checks and you can provide a default value in the second parameter.

The drawbacks are that you can't use it for arrays and maybe it's a little bit verbose (compared to $_GET['title']).

Upvotes: 5

acorncom
acorncom

Reputation: 5955

They'll automatically be available in your action as $_GET variables. Yii handles parsing them for you as part of the CHttpRequest object

Upvotes: 0

Dawlys
Dawlys

Reputation: 188

Look the function parse_str, it would worked and if not, look parse_url but it's not necessary for what you want to do.

Upvotes: 1

Related Questions