使用 shell 的 cronjobs cakephp,需要帮助

发布于 2024-10-31 02:04:05 字数 960 浏览 3 评论 0 原文

我正在 cakephp 中创建一个 shell 来打印模型中的数据,遵循有关 的教程创建外壳和任务

class ReportShell extends Shell {
    var $uses = array('Report');
    function main() {
        $reports = $this->Report->findAll();
        foreach($reports as $report) {
            $this->out('Report Name: ' . $report['Report']['name'] . "\n");
        }

        $this->out("Total Reports: " . count($reports) . "\n"); 
    }
}

但是当我在控制台上输入 $cake report 时,我收到此错误消息:

Fatal error: Unable to load DataSource file dbo\dbo_mysql_ex.php in 
C:\xampp\htdocs\cake_test\core\cake\libs\model\connection_manager.php on line 178

知道我应该如何解决这个问题吗?

更新: 按照@olezhek的建议,我编辑了我的database.php文件并使用“mysql”而不是“mysql_ex”,我确实收到了不同的错误消息,它指出我在我什至没有加载的模型上有一个未定义的函数我的报告外壳,这怎么可能?

谢谢

注意:我已经构建了数据库以及表格(报告)、字段和条目,并且我设法使用浏览器查看表格条目。

i am creating a shell in cakephp to print a data from a model, following this tutorial about Creating Shells & Tasks

class ReportShell extends Shell {
    var $uses = array('Report');
    function main() {
        $reports = $this->Report->findAll();
        foreach($reports as $report) {
            $this->out('Report Name: ' . $report['Report']['name'] . "\n");
        }

        $this->out("Total Reports: " . count($reports) . "\n"); 
    }
}

but then when i typed $cake report on the console, i get this error message:

Fatal error: Unable to load DataSource file dbo\dbo_mysql_ex.php in 
C:\xampp\htdocs\cake_test\core\cake\libs\model\connection_manager.php on line 178

any idea how should i fix this?

UPDATE:
following @olezhek suggestion, i have edited my database.php file and use "mysql" instead of "mysql_ex", i am indeed getting a different error message, which stated that i have an undefined function on a model that i didnt even load on my report shell, how is this possible ??

thanks

NOTE: i have build the database along with the table (reports), the fields and entries, and i am manage to view the table entries using the browser.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

許願樹丅啲祈禱 2024-11-07 02:04:05

我认为您正在尝试使用自定义 mysql 驱动程序(例如,用于调试查询)。您应该在 /app/config/database.php 中将驱动程序名称更改为“mysql”。或者,如果您仍然想跟踪查询,则应该创建 /app/models/datasources/dbo/dbo_mysql_ex.php 并从此处放置代码 http://bin.cakephp.org/saved/32872 进入其中。

I think that you're trying to use custom mysql driver (for example, for debugging queries). You should change the driver name to 'mysql' in your /app/config/database.php. Or, if you still want to trace queries, you should create the /app/models/datasources/dbo/dbo_mysql_ex.php and put the code from here http://bin.cakephp.org/saved/32872 into it.

も让我眼熟你 2024-11-07 02:04:05

应该 $this->Report->findAll();不是$this->Report->find('all');?

旁注:为什么你想在 cron 中运行它,echo 不会做任何事情,因为没有人会看到它

should $this->Report->findAll(); not be $this->Report->find('all');?

side note: why would you want to run that in a cron, the echo will not do anything as nobody will see it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文