Hi, I'm only just starting a course in OOP so not up to par, but need some advice to get started on a project. I'm trying to make developing of simple Content Managed sites quicker by creating a simple code base I can reuse. I'm using Smarty, and may use PEAR or others. I will be using files and a database for persistent storage. Example pages on the site are: /index.php - 2 column layout, content managed. /contactus.php - 1 column layout, static /aboutus.php - 1 column layout, content managed. /customPage.php - variable tempalte, content managed /news/index.php?article=my_article They will all have a standard menu. At this point I've done all the HTML and smarty code, and just need to send pages the following data: - $currentPage - $nav_pages[] = array('ref'=>'desc') - $html_title - $html_keywords - $html_description - $column1content - $column2content - $templatelayout = '1col_main' || '2col_main' etc At this point you might want to stop reading and make your suggestion lol cos here comes what I've thought of doing, or thought processes I've followed... I could have a Page object, containing a property for each of the variables listed above. Complications would be: 1) Sometimes not all of the page object is required - the Navigation. ie Just cos a page has a navigation tab listing 10 pages, I don't want 10 whole pages worth of data loaded, just the 'ref' and 'desc' for each page. 2) The properties would vary depending on the template of the page. $column2content is not required for 1col_main layout. Pausing to recover from brain ache lead to considering what answers might lie elsewhere, so I thought about some other possible objects, or structures, and behaviours but really just ended up with random Ideas with absolutely no foundation! class 2Col Extends Page; class Navigation extends PageSet; Site.mainNav = new Navigation(); Site.configVars (needing persistent storage) and some potential methods: Nav.getPageRefsToNamesAssoc(); Site.getWholePage($ref) Site.getCurrentPage(); What I would most like (I think) is some pointers about merging best practice for OOP, PHP, DB/file storage, and a pinch of web design - I imagine previous experience plays a huge role here. Suggestions for Objects/heirarchies/properties/behaviours welcome!! Thanks Jody
I wish I could help you, I really do. But sadly, my OOP sucks. All I know is java, and I don't know a whole lot. What I do is procedural php. Sorry? I have a big book, called Secure PHP Development. And it has 50 secure applications in it, all coded in OOP. When I need to do something with OOP, I use that book as a reference. Good luck!
Jody: It is not possible to answer your questions without having worked on your application for some time. However, I can tell you that there is more than one good way to do it. I would not worry too much about the OOP buzzword. Think solid code vs. some particular design model. Is it reusable? Is it easy to maintain? Is it modular enough to where you could swap parts without breaking the application? Have you put things in functions so that if you need to change how something works you only need to do it once? Can you read and understand your code without much comments in it? If yes, the design is good enough, be it strict OOP, procedural only, or a mix.
You are on the right track with the application design. This layout-template based content presentation is the way to go. I have built a lot of applications in this manner, and the results were always good. I have 2 suggestions for you : 1) Do not use smarty, or any other template-compilation techniques. These are a load of useless scripts that seem to make your work easier, but they actually don't. You seem to care about optimization, worrying about finding the best way to implement that page object. A single object is just fine. Just stop using smarty, and you will gain 10 times more speed than you would by implementing more objects. What's the difference between a php foreach, and a smarty foreach ? None ! 2) You really should use also a url rewriting technique with your framework.
Thanks for your response Bibel - I decided to use smarty as an experiment and I have found that it seems to make it easier to avoid repeating common html code such as template styles for different pages as well as forcing a separation between presentation and business logic, and I kind of made the decision that any speed penalties were worth it, even though I don't know exactly what the time difference is. Fair point about the difference between a php and smarty foreach loop, but it's a new toy I think I will stick with for a while lol. URL rewriting would be nice, I was thinking about it but I don't think many hosting companies support mod_rewrite, is there an alternative? What I might do now that you mention it is use smarty's caching etc as a buffer for my unweildy business logic code where possible - but processing time is not my main concern, more readable code than anything else I think, finding a happy medium between oop (etc) theory and practice, and at the least save time with future projects by having a layout to work from, or at best, having code I can reuse with nothing but a little configuration. (Optimism!!) Thanks again!