/    Sign up×
Community /Pin to ProfileBookmark

We are working on redesigning our web page which uses PHP. Right now most of the pages that I have designed follow a pretty simple format which gets complicated in the details but the overall flow is pretty simple. Each page has essentially 3 sections.

The first is a PHP switch statement that performs the appropriate “action” based on the POST method. Things such as add a record, delete a record, update a record.

Second, there is more PHP which querys the database and builds the HTML placing it in variables. A simple page may be stored in only one variable: $HTML, but normally there will be more so I can move things arround easily later.

Thirdly, is the actual HTML portion where all the $HTML variables created in section 2 are usually put into a table resulting in the final layout of the page.

What I would like to discuss, which may be beyond the scope of this board, is how to approach this in an OOP way using classes, objects, properties, and methods, and such? I understand the technical side of it well enough but I just can’t get my mind around how using objects will make things better and/or easier. Maybe someone could point me to some articles that might explain what makes OOP powerful.

Thanks,

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 04.2004 — [font=arial]OOP is powerful, but not always necessary. I mean, why would you need classes and things? If the code works now, why change it? Usually OOP is only necessary in like XML or Flash integration, I believe. Anyway, you might want to check out www.zend.com and see what they've got to say about it. They've got some slick tutorials there. ?[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@Khalid_AliMar 05.2004 — [i]Originally posted by Jona [/i]

[B][font=arial] Usually OOP is only necessary in like XML or Flash integration,[/font]



[b][J]ona[/b] [/B]
[/QUOTE]


OO Design can be implemented in many situations,such as in this case,wher eyou need to reuse your code over and over.

Here is what I'd do,break down the code in your php into blocks which may be used over and over in all pages,

then create a class or classes that will perform every task and then justinclude those/that class in all the pages.
×

Success!

Help @patpawlowski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...