【发布时间】:2023-03-28 21:01:01
【问题描述】:
我正在尝试使用 cakephp shell 为我的应用程序实现一项任务。该任务涉及运行一个长时间运行的进程(因此需要使用 shell)。
该函数需要我在一个名为 CommonComponent 的组件中使用一个函数
不幸的是,每当我尝试包含该组件时,我都会收到以下错误 PHP 致命错误:在 /var/www/nginx-test/app/Controller/Component/CommonComponent.php 中找不到类“组件”
这里是被调用的 CronShell 类
class CronShell extends AppShell {
public function main() {
$this->out('Hello world.');
// $this->out(phpinfo());
}
public function test()
{
$this->out('Before Import');
App::import('Component', 'Common');
$this->out('Import complete');
// $this->Common=ClassRegistry::init('CommonComponent');
$this->Common =new CommonComponent();
$this->out('Initialization complete');
$this->Common->testCron();
$this->out('FunctionCall complete');
//$this->Common->saveCacheEntry("name","value");
}
}
CommonComponent类存储为app/Controller/Component/CommonComponent.php,如下
class CommonComponent extends Component
{
function testCron()
{
$this->out('Hello world from Component.');
}
}
有什么想法吗?
【问题讨论】:
-
考虑更新接受的答案?