易1
大多数其他答案都是错误的。发帖人要求提供没有(某些)$_GET 参数的 url。
这是一个完整的细分(为当前活动的控制器、模块或不创建 url):
// without $_GET-parameters
Yii::app()->controller->createUrl(Yii::app()->controller->action->id);
// with $_GET-parameters, HAVING ONLY supplied keys
Yii::app()->controller->createUrl(Yii::app()->controller->action->id,
array_intersect_key($_GET, array_flip(['id']))); // include 'id'
// with all $_GET-parameters, EXCEPT supplied keys
Yii::app()->controller->createUrl(Yii::app()->controller->action->id,
array_diff_key($_GET, array_flip(['lg']))); // exclude 'lg'
// with ALL $_GET-parameters (as mensioned in other answers)
Yii::app()->controller->createUrl(Yii::app()->controller->action->id, $_GET);
Yii::app()->request->url;
当您没有相同的活动控制器时,您必须像这样指定完整路径:
Yii::app()->createUrl('/controller/action');
Yii::app()->createUrl('/module/controller/action');
查看 Yii 构建 url 的指南:http ://www.yiiframework.com/doc/guide/1.1/en/topics.url#creating-urls