You cannot create the URL in the console application until you get the following error:
'Configure correctly UrlManager::scriptUrl
when starting the console application.
To get rid of this message and work with UrlManager
, in the configuration file console.php
add the following configuration:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'scriptUrl' => 'http://path/to'
]
, :
echo \Yii::$app->getUrlManager()->createAbsoluteUrl('test/test');
echo "\n";
echo \yii\helpers\Url::toRoute('test/test');
:
http://path/to?r=test%2Ftest
http://path/to?r=test%2Ftest