• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

yii的方法createUrl生成路径问题

php 搞代码 4年前 (2022-01-23) 18次浏览 已收录 0个评论
文章目录[隐藏]

发现用 $this->createUrl(‘index/archives’) 后成的路径是相对的这种 。 不是 http://www.xxxx.com/ 绝对的这种。请问一下有什么方法让 createUrl生成绝对的吗?我在网上找了好久都没有找到方法

回复讨论(解决方案)

使用 createAbsoluteUrl()就可以了。
$route = ‘index@本文9来源gao($daima.com搞@代@#码8网^搞代gaodaima码/archives’;
$params=array();
$url=$this->createAbsoluteUrl($route,$params);

http://www.yiiframework.com/doc/api/1.1/CController#createAbsoluteUrl-detail

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;	}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:yii的方法createUrl生成路径问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址