How to reuse common code in PHP oop class?

Login or register to post comments
6 replies [Last post]
vargasandor's picture
Offline
Joined: 03/10/2010

I would like to reuse code in PHP classes. Please help me with this.
On one of my sites every form has a lot of common functionality, which I implement with objects declared in that form. But the functionality is the same across all the pages.
How can I declare them in a common way? That would save me from change in a lot of pages but in one common file.
I am beginner in PHP OOP, but versed in Java OOP.

Thank You for Your help.

Sanyi.

Offline
Joined: 03/31/2008

Similar to any OOP language, refactor that functionality into an external class you can utilize in both forms.

Metacontrols are an example of refactoring common GUI components out of the form level and into a helper class.

alex94040's picture
Offline
Joined: 11/06/2008

Sanyi, tell us what that common functionality does - we'll then try to give you a precise advice about where to put that shared logic.

vargasandor's picture
Offline
Joined: 03/10/2010

Thank You for Your question.
I made a QForm for every page on the site (www.cardemoworld.com).
But every page has a quick menu, which takes data and links from database, has a New Cars zone, which also takes data from database, these are all common for almost all pages.
Currently I create all the variables in the zzz.php files, and present it in the zzz.tpl.php files, separately.
A change in on of the modules this way involves changing separately the server-side code and the presentation code.
I would like to have the common parts in one single representation, but I don't know why.
I know I don't say too big foolish, becouse I can do it in Java, but I am a beginner in PHP.

Thank You for Your answers.

vargasandor's picture
Offline
Joined: 03/10/2010

Thank You. I will try it.
Sanyi.

alex94040's picture
Offline
Joined: 11/06/2008

Sanyi,

I encourage you to consider placing this shared functionality into a QPanel. See more on how QPanels work: http://examples.qcu.be/assets/_core/php/examples/multiple_qform/intro.ph

vargasandor's picture
Offline
Joined: 03/10/2010

This link is not working.
A don't like qpanel, from my experience, it gives a reaaly big overhead to the processors.
Thank You anyway.
Sanyi.