The path generated by createUrl in yii method

Source: Internet
Author: User
The path generated by createUrl in yii method is found to be relative to the path generated by using $ this-> createUrl ('index/archives. This is not an absolute form of www.xxxx.com. Is there any way to generate an absolute createUrl? I haven't found a solution for a long time on the Internet.


Reply to discussion (solution)

Use createAbsoluteUrl.
$ Route = 'index/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;elsereturn Yii::app()->getRequest()->getHostInfo($schema).$url;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.