cakephp-2.0 - CakePHP 控制台给出错误 "Undefined index: HTTP_HOST"

标签 cakephp-2.0 settings cake-console

我在 APP/Config/config.php 中有一个设置我有一行定义主机:

define('SITE_URL','http://'.$_SERVER['HTTP_HOST']);

每当我运行蛋糕控制台时,我都会收到错误:

Notice (8): Undefined index: HTTP_HOST [APP/Config/config.php, line 144]
Code Context
include - APP/Config/config.php, line 144
PhpReader::read() - CORE/Cake/Configure/PhpReader.php, line 80
Configure::load() - CORE/Cake/Core/Configure.php, line 267
include - APP/Config/bootstrap.php, line 190
Configure::bootstrap() - CORE/Cake/Core/Configure.php, line 92
require - CORE/Cake/bootstrap.php, line 146
ShellDispatcher::_bootstrap() - CORE/Cake/Console/ShellDispatcher.php, line 131
ShellDispatcher::_initEnvironment() - CORE/Cake/Console/ShellDispatcher.php, line 101
ShellDispatcher::__construct() - CORE/Cake/Console/ShellDispatcher.php, line 57
ShellDispatcher::run() - CORE/Cake/Console/ShellDispatcher.php, line 68
[main] - APP/Console/cake.php, line 33

为什么会出现这个问题,我该如何解决这个问题?

最佳答案

这是因为您是从控制台运行的,(cakePHP 使用 PHP-CLI)

$_SERVER['HTTP_HOST']

它仅在从浏览器(网络服务器)运行时填充

关于cakephp-2.0 - CakePHP 控制台给出错误 "Undefined index: HTTP_HOST",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18790739/

相关文章:

php - Cakephp 在 Centos 生产服务器上安装 Bake

php - Cake Console 无法在 Mac OS X Lion 上运行

cakephp - 在CakePHP中本地化timeAgoInWords

visual-studio-2012 - 使用不同的设置启动 Visual Studio

java - 如何在android中使用工具栏创 build 置

ruby-on-rails - Rails - 处理全局站点设置

cakephp - file_put_contents Cakephp 错误 + fatal error : Allowed memory size

cakephp - Controller cakephp 2 中的全局变量

php - Paypal 休息api