Welcome Guest, Not a member yet? Register   Sign In
Using a CI class from a unix command line
#1

[eluser]Unknown[/eluser]
Wondering if it is possible to run a CI class from unix command line? As of now, the class extends Controller because the class is part of a much larger program. If you try 'php myfile.php' at the unix command line, it produces the following error:

------------
Fatal error: Class myfile: Cannot inherit from undefined class controller in ci/system/application/controllers/myfile.php on line
------------

Is it possible to use just one class of a much larger program and execute it from the unix command line?
#2

[eluser]ejangi[/eluser]
If your controller is extending the base Controller (which also extends the CI_Base class), you will have to load both of those files as well. What you will probably find easier to do is create a copy of the index.php file and set it up specifically for your command-line needs. This would take a lot of trial and error to get right I imagine, but back to your original answer: No, if the class is extending another class you can't just run in from the command line. And even if you try to load a file with a class that doesn't extend anything else, you still have to instantiate that class for it to do anything:
Code:
$instance_of_class = new MY_Class();
#3

[eluser]champs[/eluser]
Using CodeIgniter from the command line.

If you're not sure if it's being used from the command line or via web, php_sapi_name() is your friend.




Theme © iAndrew 2016 - Forum software by © MyBB