Run Controller method from command line

I have a simple "Hello World" Im trying to execute from the command line as per CI instructions

php index.php selection_schedule

I get this error

An uncaught Exception was encountered

Type: Error
Message: Call to undefined function uri_path()
Filename: /var/www/html/fuel/modules/fuel/hooks/Fuel_hooks.php
Line Number: 90

Backtrace:
File: /var/www/html/fuel/modules/fuel/core/MY_Hooks.php
Line: 196
Function: offline

    File: /var/www/html/index.php
    Line: 375
    Function: require_once

Ideas on how to run from command line

Comments

  • Does your fuel/application/config/autoload.php file have url as one of the $autoload['helper']?

    the uri_path() function should automatically get loaded. FUEL extends the CI helper and includes that function in the fuel/application/helpers/MY_url_helper.php.

  • url is in the autoload['helper'] but the only thing in the fuel/application/helpers/MY_url_helper.php file is

    require_once(FUEL_PATH.'helpers/MY_url_helper.php');

    Nothing else.

  • If you follow that path, it will go to the file that has that function. I just created a simple "Test.php" controller and ran php index.php test and it worked fine without error so I'm unfortunately not sure why you'd be seeing that error.

  • I cannot run any controllers from command line if the environment is in production. It works fine in development. How can I over ride this to run fire off a controller from the command line php index.php Send_controller

  • Are you getting any errors? Also, can you run any php script on production?

  • The ENVIRONMENT is in production and I don't see any errors because in production has error suppression on but I will put error_reporting(E_ALL); at the top of my controller file and run it and see what I get. Ill get back to you

  • I wasn't able to get it to throw an error nor print_r() the results of a query in PRODUCTION mode. DEVELOPMENT it would give me the query results.
    Was it intended to not run crons in production mode?

  • FUEL uses the native CI CLI feature and any restrictions on running in CLI mode would need to be in the Controller code that's created. What do you get when you run php -v? Also, are you able to call a simple controller that doesn't touch the database (note that a database connection will happen automatically if the fuel_mode is set to auto in thefuel/application/config/MY_fuel.php)?

  • edited July 2019

    PHP version 7.1.30 (cli)
    I just made the index method echo Hello World. Same results. No print to screen in production. Would print to screen in development.

    I created another controller:

    <?php

    error_reporting(E_ALL);
    class Test extends CI_Controller
    {

    function __construct()
    {
        parent::__construct();
    }
    
    
    public function index(){
        echo "Hello World";
    }
    

    }

    Same result. Nothing in prod. runs in dev

  • I'm curious if this is a FUEL issue or a server config issue. Is it possible for you to test a fresh CI installation on the server with the same controller?

  • I tested this on my dev environment A little web server in house and had the same results the Test.php controller did not return any results when the environment is in production. It does return in development. So I don't see it being a server issue. Anything I should try next?

  • And you used the following?
    php index.php test

  • Yes that is what I ran in the command line

Sign In or Register to comment.