Converting a templating system to OOP

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Converting a templating system to OOP

Post by vigge89 »

I'm thinking about converting my current project - a cms with an inbuilt templating system and parser - to OOP. The idea I'm having is to make page-handling (loading a page, managing variables and templates, etc.) into a class (maybe a static one?), with an parser-class (parses the templates, changing output based on contents of $page->variables, etc.) which extends it. The question is, is this a good idea? I think handling and extending the page-class with different things (for example the parser) would be a lot easier, but I want your ideas on this. I'm storing the templates in a database, and have the different functions in php-files.

I'm interested in your ideas, do you think it's good, do you have any other idea on how to design the cms, have you developed your own cms and got hints or tips? Everything is appreciated :)

Thanks //vigge
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

depending how far along you are, you might want to think about scrapping rather than converting. You don't want your current code to limit the strength of your new code.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

magicrobotmonkey wrote:depending how far along you are, you might want to think about scrapping rather than converting. You don't want your current code to limit the strength of your new code.
"It's important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time"

http://www.joelonsoftware.com/articles/ ... 00069.html
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

yea that's why i said "depending how far along you are." plus its his own code, so some of the stuff from that article doesn't apply. It does make some good points though.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

It's a good idea to keep classes nice and tight, each doing just one thing.

For a Foo view, I'd probably have a FooViewData object (which gathers data for the Foo view from domain objects - or direct from the data acess layer if there's no domain logic to do) and output strategies: FooViewHtmlPrinter, FooViewCommandLinePrinter, and so on.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

Hm better scrapping

Imagine for example that even application design is different in PHP5. Now using class types like abstract and interface (and not only) you can create and implement a stronger structure.
Post Reply