createAbsoluteUrl() public method

This method prepends the URL created by UrlManager::createUrl with the [[hostInfo]]. Note that unlike [[\yii\helpers\Url::toRoute()]], this method always treats the given route as an absolute route.
See also: createUrl()
public createAbsoluteUrl ( string | array $params, string | null $scheme = null ) : string
$params string | array use a string to represent a route (e.g. `site/index`), or an array to represent a route with query parameters (e.g. `['site/index', 'param1' => 'value1']`).
$scheme string | null the scheme to use for the URL (either `http`, `https` or empty string for protocol-relative URL). If not specified the scheme of the current request will be used.
return string the created URL
Esempio n. 1
0
 public function testCreateAbsoluteUrl()
 {
     $manager = new UrlManager(['baseUrl' => '/', 'hostInfo' => 'http://www.example.com', 'cache' => null]);
     $url = $manager->createAbsoluteUrl(['post/view', 'id' => 1, 'title' => 'sample post']);
     $this->assertEquals('http://www.example.com?r=post%2Fview&id=1&title=sample+post', $url);
     $url = $manager->createAbsoluteUrl(['post/view', 'id' => 1, 'title' => 'sample post'], 'https');
     $this->assertEquals('https://www.example.com?r=post%2Fview&id=1&title=sample+post', $url);
     $manager->hostInfo = 'https://www.example.com';
     $url = $manager->createAbsoluteUrl(['post/view', 'id' => 1, 'title' => 'sample post'], 'http');
     $this->assertEquals('http://www.example.com?r=post%2Fview&id=1&title=sample+post', $url);
 }
Esempio n. 2
0
 public function createAbsoluteUrl($params, $scheme = null)
 {
     $params = (array) $params;
     if (!isset($params['language'])) {
         $params['language'] = Yii::$app->language;
     }
     return parent::createAbsoluteUrl($params);
 }
 public function createAbsoluteUrl($params, $scheme = null)
 {
     $subDomain = 'www';
     if (isset($params[$this->subDomainKey])) {
         $subDomain = $params[$this->subDomainKey];
         unset($params[$this->subDomainKey]);
         $this->setHostInfo('http://' . $subDomain . '.' . $this->baseDomain);
     }
     return parent::createAbsoluteUrl($params, $scheme);
 }
Esempio n. 4
0
 public function createAbsoluteUrl($params, $scheme = null)
 {
     if (Yii::$app->language != Yii::$app->sourceLanguage) {
         $params += ['language' => Yii::$app->language];
     }
     return parent::createAbsoluteUrl($params, $scheme);
 }
Esempio n. 5
0
 /**
  * Tests if hash-anchor present
  *
  * https://github.com/yiisoft/yii2/pull/9596
  */
 public function testHash()
 {
     $manager = new UrlManager(['enablePrettyUrl' => true, 'cache' => null, 'rules' => ['http://example.com/testPage' => 'site/test'], 'hostInfo' => 'http://example.com', 'scriptUrl' => '/index.php']);
     $url = $manager->createAbsoluteUrl(['site/test', '#' => 'testhash']);
     $this->assertEquals('http://example.com/index.php/testPage#testhash', $url);
 }
Esempio n. 6
0
/**
 * @param string|array $params use a string to represent a route (e.g. `site/index`),
 * @param string $scheme the scheme to use for the url (either `http` or `https`). If not specified
 * @param \yii\web\UrlManager $urlManager
 * @return string
 */
function aurl($params, $urlManager = null, $scheme = null)
{
    return $urlManager instanceof \yii\web\UrlManager ? $urlManager->createAbsoluteUrl($params, $scheme) : urlManager($urlManager)->createAbsoluteUrl($params, $scheme);
}