Jump to content

Module with more than one class? (the newb again)


swissdoode
 Share

Recommended Posts

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 ;)

Link to comment
Share on other sites

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

×
×
  • Create New...