I'm trying to run code from the CLI just as said in the CI documentation, but for some reason, maybe because of using the HMVC extension, it won't enter the specified controller.
I have found no additional documentation about CLI execution in the HMVC extension site.
Does anyone know how to deal with this?
The code here:
/**
* application/controllers/Cron.php
* This is just a wrapper controller to use an HMVC module using the basic CLI syntax for CI
*
*/
class Cron extends MX_Controller
{
public function generatepdfs($start_date = null, $end_date = null)
{
echo 'Not reached'; exit;
$this->load->module('facturation/documentscontroller');
$this->documentoscontroller->generatepdfs($start_date, $end_date);
}
}
No matter if I run this from the document root:
php index.php cron generatepdfs
or this:
/usr/bin/php -f /home/user/public_html/index.php cron generatepdfs
It will not display 'Not reached'.
It does if I run it from the browser.
These are some of the errors output to the console:
Unable to locate the specified class: Session.php
I have an overriden Session library MY_Session in application/libraries/session/MY_Session.php that works perfectly in a browser. If I move this file one directory upwards this error won't display again in the console, but it won't work in the browser. It is autoloaded by the way.
A workaround for this I don't like at all: copy the same file in both locations.
Next error:
PHP Fatal error: Class 'CI_Preferencias' not found in /home/mysite/public_html/system/core/Common.php on line 196
I have a custom library called Preferencias, which is also autoloaded, in application/libraries/Preferencias.php
Again, this works perfectly in the browser. However, from CLI it seems to search for a CI_Preferencias library, which doesn't exist. If I rename it to CI_Preferencias, and autoload "CI_Preferencias", CI will search for a class called CI_CI_Preferencias from CLI.
I'm not sure if I'm missing something, or there's an actual bug in CI, or the HMVC module is messing with it.
Could anyone help me?? This is getting me crazy since I must use CLI actions scheduled from cronjobs and I feel completely lost.
application/modules/your_module_name/controllers/Cron.php
– Marlanamarlaneclass Cron extends MX_Controller
. Based on your description ofMY_Session
, should that beMX_Controller
orMY_Controller
? – CortexMX_Controller
looked like a typo, based onMY_Controller
. (An "X" being used where a "Y" was expected.) However, it sounds like it's a deliberate inheritance chain. – Cortex