Cake 2.0 CLI模式错误“Undefined HTTP_HOST”

时间:2012-11-28 05:20:29

标签: shell cakephp command-line-interface

我正在蛋糕控制台上运行shell脚本。能够运行 HelloShell 但是HTTP_host上的错误未定义app/config/core.php以获取以下代码:

class HelloShell extends AppShell {
    public $uses=array('Test');
    public function main() {
        $this->out('Hello Kundan.');
    }
     public function hey() {
       $this->Test->save($data['Test']['name']='Kundan');
    }
}

显示错误消息:

PHP notice: undefined index HTTP_HOST in 
C:\wamp\www\myapplication\app\Config\core.php on line 231. 

当我打开该文件时,我发现第231行Configure::write('Website_root',$_SERVER['HTTP_HOST']);

1 个答案:

答案 0 :(得分:0)

我复制了你的代码,运行良好。

你把HelloShell.php文件放在哪里?以及如何运行代码?

通常的方法是,将HelloShell.php文件放在app/Console/Command/目录中并按Console/cake hello

运行

也尝试修改你的代码:

class HelloShell extends AppShell {

    public $uses=array('Test');

    public function main() {
        $this->out('Hello Kundan.');
        $this->hey();
    }
     public function hey() {
       $data['Test']['name']='Kundan';
       $this->Test->save($data);
    }
}