yii的方法createUrl生成路径问题

golmjie 2014-06-23 03:23:52
发现用 $this->createUrl('index/archives') 后成的路径是相对的这种 。 不是 www.xxxx.com/ 绝对的这种。请问一下有什么方法让 createUrl生成绝对的吗?我在网上找了好久都没有找到方法
...全文
343 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2014-06-24
  • 打赏
  • 举报
回复
https://github.com/yiisoft/yii/blob/1.1.14/framework/web/CController.php#L980

/**
	 * Creates an absolute URL for the specified action defined in this controller.
	 * @param string $route the URL route. This should be in the format of 'ControllerID/ActionID'.
	 * If the ControllerPath is not present, the current controller ID will be prefixed to the route.
	 * If the route is empty, it is assumed to be the current action.
	 * @param array $params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
	 * @param string $schema schema to use (e.g. http, https). If empty, the schema used for the current request will be used.
	 * @param string $ampersand the token separating name-value pairs in the URL.
	 * @return string the constructed URL
	 */
	public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
	{
		$url=$this->createUrl($route,$params,$ampersand);
		if(strpos($url,'http')===0)
			return $url;
		else
			return Yii::app()->getRequest()->getHostInfo($schema).$url;
	}
傲雪星枫 2014-06-24
  • 打赏
  • 举报
回复
使用createAbsoluteUrl()就可以了。 $route = 'index/archives'; $params=array(); $url=$this->createAbsoluteUrl($route,$params); http://www.yiiframework.com/doc/api/1.1/CController#createAbsoluteUrl-detail

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧