2

我正在尝试使用以下命令在 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 作业时得到的反馈: 致命错误:第3行的/home/mystuff/public_html/application/controllers/scripts.php中未找到 Class 'CI_Controller'

我找不到任何证据表明有人和我有同样的问题 - 围绕这个问题的大多数主题都和我一样,而且它显然工作得很好。

提前非常感谢!

4

3 回答 3

4

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

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

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

于 2012-12-14T00:08:05.353 回答
0

没有CI_Controller课。CRON作业仅加载该文件,因此找不到任何CI_Controller. 您将不得不CI_CONTROLLER在类定义之前包含该类

像这样的东西

<?php

require_once('path_to_CI_controller');

class Scripts extends CI_Controller
{
    ...
于 2012-12-14T00:07:34.093 回答
0

在路由文件中使用了以下内容,它起作用了!我想通了。我的新手问题是需要配置参数。

例如

`$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 line> php.exe index.php pdfscript runmethod 文件名

于 2015-02-20T13:58:01.020 回答