In Console app createAbsoluteUrl
does not work. Do I need to change some setting in config file to made it work.
As per my understanding the request component is not available in Console app. So where do I specify the base URL.
I did not find anything on this. Any help would be appreciated. Thank you.
You are unable to create URL in console application while you will receive the following error:
'Please configure
UrlManager::scriptUrl
correctly as you are running a console application.'
To get rid of this message and work with UrlManager
, in your console.php
config file, add the following configuration:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'scriptUrl' => 'http://path/to'
]
Now, if you write the following lines in your console app:
echo \Yii::$app->getUrlManager()->createAbsoluteUrl('test/test');
echo "\n";
echo \yii\helpers\Url::toRoute('test/test');
You will see the following output:
http://path/to?r=test%2Ftest
http://path/to?r=test%2Ftest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With