Cron作业 - Codeigniter - 找不到类'CI_Controller'

时间:2012-12-14 00:02:28

标签: php codeigniter cron

我正在尝试使用此命令在cpanel上创建一个cron作业:

/usr/bin/php -q /home/mystuff/public_html/application/controllers/scripts.php scripts release_reviews

我的scripts.php控制器如下:

<?php

class Scripts extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');

    }

    public function release_reviews()
    {
        echo release_reviews(); //where the actual logic will sit once the cron job works
    }
}

我尝试运行cron作业时得到的反馈: 致命错误 /home/mystuff/public_html/application/controllers/scripts.php 3
中找不到“CI_Controller”类/>

我找不到任何证据表明任何人都有与我相同的问题 - 围绕此问题的大多数主题都和我一样,并且显然效果很好。

提前多多感谢!

3 个答案:

答案 0 :(得分:3)

要通过命令行访问CodeIgniter,您需要调用index.php文件,而不是您的控制器。

php /home/mystuff/public_html/index.php scripts release_reviews

文档:http://ellislab.com/codeigniter/user-guide/general/cli.html

答案 1 :(得分:0)

没有CI_Controller类。 CRON个作业只加载该文件,因此无法找到任何CI_Controller。您将不得不在类定义

之前包含CI_CONTROLLER

像这样的东西

<?php

require_once('path_to_CI_controller');

class Scripts extends CI_Controller
{
    ...

答案 2 :(得分:0)

在路线文件中使用以下内容并且它有效! 我想通了。我的新手问题是需要配置参数。

e.g。

`$route['pdfscript/runmethod']  = "batch/pdfscript/runmethod";
$route['pdfscript/runmethod/(:any)'] = "batch/pdfscript/runmethod/$1";'

`pdfscript.php
<?php 
class pdfscript extends CI_Controller {
public function runmethod($file) {
echo $file;
.....`

cmd行&gt; php.exe index.php pdfscript runmethod filename

相关问题