CreateAbsoluteUrl does not work in a console application

The console application createAbsoluteUrldoes not work. I need to change some settings in the configuration file for it to work.

In my opinion, the request component is not available in the console application. So where to specify the base URL.

I did not find anything about this. Any help would be greatly appreciated. Thanks.

+4
source share
1 answer

You cannot create the URL in the console application until you get the following error:

'Configure correctly UrlManager::scriptUrlwhen starting the console application.

To get rid of this message and work with UrlManager, in the configuration file console.phpadd 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
+8

Source: https://habr.com/ru/post/1612897/


All Articles