在Yii控制台应用程序中获取基本URL [英] Get base URL in Yii console application
问题描述
如何在Yii CConsoleApplication
应用程序中获取基本URL?
How to get base URL in a Yii CConsoleApplication
application?
我尝试了Yii::app()->request->getBaseUrl(true)
并最终出现以下错误.
I tried Yii::app()->request->getBaseUrl(true)
and ended up with the following error.
未定义索引:SERVER_NAME(/var/www/yii/framework/web/CHttpRequest.php:279)
Undefined index: SERVER_NAME (/var/www/yii/framework/web/CHttpRequest.php:279)
推荐答案
控制台应用程序中没有请求对象. Web应用程序中的请求对象,如果您正在生成,则该对象为 CHttpRequest 的实例在离线任务中的URL,您必须以其他方式配置baseUrl,也许是在配置中:
There is no request object in a console application. the request object in a web application its an instance of CHttpRequest, if you are generating URLs in an offline task, you have to configure the baseUrl in some other way, perhaps in the configuration:
"request" => array(
'hostInfo' => 'http://localhost',
'baseUrl' => '/yii-project/index-test.php',
),
// OR
'request' => array(
'hostInfo' => 'http://localhost',
'baseUrl' => '/yii-project',
'scriptUrl' => 'index-test.php',
),
这篇关于在Yii控制台应用程序中获取基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!