如何在没有PATH格式的YII中获取查询字符串值?

如何在没有PATH格式的YII中获取查询字符串值?

问题描述:

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?

我有以下网址, p>

  www.example。  ?COM / index.php的R =建议/创建和ID = 184 
标题=废墟%20of%20Mahabalipuram 
&安培; URL = HTTP://localhost/index.php/mediadetail/index/184 
 代码>   pre> 
 
 

我需要获取标题和网址 strong>这些是查询字符串参数。 p>

有没有人在Yii中获取查询字符串中的值? p> div>

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']).

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.

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