Jump to content

How to use public function from module in another module


hakeryk2

Recommended Posts

Hello,

 

I have question. I wrote an function which I like in module A.

Right now I am developing module B and I would love to use this function from A in B without copying it.

 

Any Idea how to achieve this?

 

Instantiate the class (the module class) and call your function:

$module = new YourModule();
$module->function();
  • Like 1
Link to comment
Share on other sites

I tried with 

 

$module = new Cwarehouse();

but after that I am getting 

 

 

Class 'Cwarehouse' not found in Mylocalhostaddress\modules\checkavailability\checkavailability.php on line 332

 

this is proper name of my class because in this module I used

class Cwarehouse extends Module {

}

This is funny because even my IDE is getting functions from this class when I use $module->getImagePath();


Any help?

--------------------------------------------------------------------------------------

EDIT with solution:

 

I just added on the beggining and everythings works now. Thank You for Your help.

include '../modules/cwarehouse/cwarehouse.php';
Edited by hakeryk2 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 year later...
On 3/24/2017 at 2:38 PM, hakeryk2 said:

EDIT with solution:

 

I just added on the beggining and everythings works now. Thank You for Your help.


include '../modules/cwarehouse/cwarehouse.php';

To avoid any path errors, you should call this instead :

include_once _PS_MODULE_DIR_ . 'MODULENAME/MODULENAME.php';

 

Link to comment
Share on other sites

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...