Jump to content

[SOLVED] Load module class in controller


gr4devel

Recommended Posts

Hi community, today my problem is concerning an override.

 

I need to override a controller and call in the override a method of the module that overrides the controller.

 

If I try to include the php file with

 

 include_once('.'._MODULE_DIR_.'mymodule/mymodule.php');

 

I get an error on the staging server when I try to install the module (PS simply doesn't find the module while copying the override in the root override directory).

If I try with

 

 include_once(_MODULE_DIR_.'mymodule/mymodule.php');

 

I get an error when the override is called.

 

To conclude if I try to remove the inclusion of the file I get

 

Fatal error: Class 'MyModule' not found in /path/to/controller

 

What should I do? :(

 

P.S: I need to instatiate the module because I need to call one of its method that rely on one of its property...

Edited by gr4devel (see edit history)
Link to comment
Share on other sites

Ok I solved it by moving the include_once inside the init method of the controller and by modifying the path in this way:

 

include_once(dirname(__FILE__).'/../../../modules/daneainvoiceimporter/daneainvoiceimporter.php');

 

Please if anyone has a better way to handle this situation write it down here...I really feel that what I've done is a bad thing :(

 

P.S: I'll leave the topic open till news...

Link to comment
Share on other sites

  • 1 month later...
  • 7 months later...

Hi,

 

an easier solution :

include(_PS_MODULE_DIR_.'mymodule'.DIRECTORY_SEPARATOR.'mymodule.php');

note : If you're sure to call mymodule.php just one time, prefer include to include_once (a little more greedy because check if already called).

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...