Codeigniter command line error - PHP fatal error: class 'CI_Controller' not found
P粉916553895
P粉916553895 2023-09-18 22:52:11
0
2
794

After following the instructions in the user guide, I am unable to run the test script via the command line.

My controller is located at /var/www/mysite/application/controllers/

class Tools extends CI_Controller {

    public function message($to = 'World')
    {
        echo "Hello {$to}!".PHP_EOL;
    }
}

In the browser I can access

http://mysite/tools/message/ben

This function correctly outputs "Hello ben"

From the terminal, I should be able to run:

$ php index.php tool message "Ben"

My terminal should print out: "Hello Ben"

However, I get the following error:

PHP Fatal Error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php line 233

My server is standard ubuntu LAMP. Codeigniter also comes standard and I have no problem running non-CI scripts via the command line.

My PHP is only installed in /usr/bin/php <-- This article hints at problems with running CI directly from usr/bin/php, however I am not using a shared PHP service and don't understand how this would Have an impact on how PHP executes CI scripts.

Thank you very much for your help in advance.

P粉916553895
P粉916553895

reply all(2)
P粉099985373

To resolve the error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php and check the database details like hostname, username, password, and database.

P粉262073176

solved! (Part of the) problem is CodeIgniters error logging.

In application/config/config.php, I modified the following configuration properties:

$config['log_threshold'] = 0;

This will disable logging and allow $ php index.php to execute.

If anyone can explain why CI only shows this error on CLI PHP - it might help others who run into this issue and need to resolve it via error logging.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template