Jump to content

Recommended Posts

Posted

Hi Forum

While getting to know PW, a question about modules with more than one class came up.
Let's say, I want to create a shopping cart module.
I need two classes for it: 
- the shopping cart itself
- a class for the items in the cart (I want to separate this because I want the items to have their own methods - for calculating a total, for example).

Now, I don't think I can just add the item-class to the file where I create the cart-module.
How would I do this in the module?

Thanks for any help (and your patience with a noob ;)

Posted

Ok, got it...

Apparently, the additonal class can just be added to the the php-file that contains the module...

I was under the wrong impression that a module file can only contain one class... ;)

Posted

The only difference between a module and a normal php class (besides the content) is the file extension and that classname and filename do need to match.

Posted

You could also add the class in its separate .php file and require_once (/path/to/the/external/file/) that file within your module...

  • Like 1
Posted
15 minutes ago, kongondo said:

You could also add the class in its separate .php file and require_once (/path/to/the/external/file/) that file within your module...

Since we're talking modules, one needs to use a relative or dynamically assembled path, and make sure that it doesn't break when FileCompiler comes into play. Thus, if the class is only to be used by the module itself or by code that explicitely references the module, adding it to the module's file is IMHO the most reliable approach.

  • Like 1

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