2
votes

I'm trying to create a cron job on cpanel using this command:

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

My scripts.php controller is as follows:

<?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
    }
}

The feedback I get when I try to run the cron job: Fatal error: Class 'CI_Controller' not found in /home/mystuff/public_html/application/controllers/scripts.php on line 3

I can't find any evidence anyone has the same problem as me - most topics around this do the same as me and it works just fine apparently.

Thanks a lot in advance!

3

3 Answers

4
votes

To access CodeIgnter via the command line, you want to call the index.php file, not your controller.

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

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

0
votes

There is no CI_Controller class. CRON jobs only load that file, so it can't find any CI_Controller. You are going to have to include the CI_CONTROLLER class before the class definition

Something like this

<?php

require_once('path_to_CI_controller');

class Scripts extends CI_Controller
{
    ...
0
votes

Used the following in the routes file and it worked! I figured this out. My newbie problem is that the arguments need to be configured.

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 line> php.exe index.php pdfscript runmethod filename