Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron job - Codeigniter - Class 'CI_Controller' not found

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!

like image 798
Davor Avatar asked Jul 09 '26 03:07

Davor


1 Answers

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

like image 93
Rocket Hazmat Avatar answered Jul 11 '26 20:07

Rocket Hazmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!