Codeigniter HMVC from CLI: not included in the controller

I am trying to run the code from the CLI, as indicated in the CI documentation, but for some reason, perhaps due to the use of the HMVC extension, it will not go into the specified controller.

I did not find any additional documentation on running the CLI on the HMVC extension site.

Does anyone know how to handle this?

The code is 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); } } 

Regardless of whether I run this from the root of the document:

 php index.php cron generatepdfs 

or that:

 /usr/bin/php -f /home/user/public_html/index.php cron generatepdfs 

It will not display "Not reached."

This happens if I run it from a browser.

Here are some of the errors displayed on the console:

Unable to find the specified class: Session.php

I have an overridden MY_Session session library in the / libraries / session / MY _Session.php application that works fine in the browser. If I translate this file into one directory up, this error will not be displayed again in the console, but it will not work in the browser. By the way, this is autoload.

I don't like the workaround for this at all: copy the same file in both places.

The following 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 also loads automatically in application / libraries / Preferencias.php

Again, this works fine in the browser. However, from the CLI, it seems to be looking for the CI_Preferencias library, which does not exist. If I rename it to CI_Preferencias and automatically load "CI_Preferencias", CI will look for a class named CI_CI_Preferencias from the CLI.

I'm not sure if I missed something, or there is a real error in CI, or the HMVC module is messing with it.

Can anyone help me? This drives me crazy, since I have to use the CLI actions planned on cronjobs and I feel completely lost.

+6
source share
2 answers

If you added subclass_prefix to the configuration file as " $config['subclass_prefix'] = 'MY_'; ". Try MY_Preferencias.php instead of Preferencias.php

If you have not used $ config ['subclass_prefix'] = 'MY_'; and calling the session library as $ this-> load-> library ('session'); it takes its own CIs session library instead of your custom MY_Session.php

Here's a link

0
source

I think you should add constructor

 class Cron extends MX_Controller { public function __construct() { parent::__construct(); // Any conditions/triggers while constructor loads. } 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); } } 

I did not check the code. Just give it a try.

0
source

Source: https://habr.com/ru/post/1246254/


All Articles