yii的方法createUrl產生路徑問題

來源:互聯網
上載者:User
發現用 $this->createUrl('index/archives') 後成的路徑是相對的這種 。 不是 www.xxxx.com/ 絕對的這種。請問一下有什麼方法讓 createUrl產生絕對的嗎?我在網上找了好久都沒有找到方法


回複討論(解決方案)

使用 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;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.