2

我在蛋糕控制台上运行一个 shell 脚本。能够运行HelloShell以下代码出现未定义错误:HTTP_hostapp/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']);

4

1 回答 1

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);
    }
}
于 2012-11-28T12:51:01.183 回答