Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP best design practices

Tags:

oop

php

templates

Ok, have a bunch of questions that I have been thinking about the past few days. Currently I have a site that is just a bunch of PHP files with MySQL statements mixed in with PHP, HTML and CSS, basically a huge mess. I have been tasked with cleaning up the site and have made for myself, the following requirements:

  • The site needs to be efficient and well laid out (the source code), I would like to be able to write as little code as possible.
  • There has to be good separation between structure, presentation and logic.
  • For whatever reason, I can't use a framework and need to keep the code maintainable and "simple" as there will be future developers working with it.
  • There needs to be an admin section for at least a few pages.

Saying that, this is what I know about the site as it is now:

  • Consists of 10-12 pages, a few are completely static, most are dynamically driven via a database and there is a huge form for users to fill out (20-30 fields) that need to be validated and checked.
  • The hierarchy of the site is basically 5-6 main pages and then sub-pages within those.

So, knowing those things I wanted to know if anyone had any tips/suggestions as to how to go about doing this with the least amount of headaches.

  • Would an OO approach be best in this situation?
  • Since there are many static pages and the dynamic pages just need the content filled in would it be best to use some kind of basic template?

EDIT: Thanks for the answers, when I said no frameworks I basically meant anything that would require new syntax other than PHP, as whoever gets hired to work on this site after me will probably only know PHP.

like image 923
roflwaffle Avatar asked Jan 15 '09 17:01

roflwaffle


2 Answers

Here's an article about how to organize your PHP project, from Rasmus Lerdorf, the architect who created the language:

http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

Despite the popularity of OO frameworks for PHP, Rasmus advocates a less OO approach. He knows more than anyone about PHP intended usage, and how to take advantage of its architecture for high-performance websites.

edit: In response to the comment by @theman, I'll concede the article isn't a fine work of writing, but I think the content is important. Using PHP as it was intended to be used is better than struggling against its weaknesses to make it fit an OO mold.

like image 81
Bill Karwin Avatar answered Oct 22 '22 06:10

Bill Karwin


I highly recommend the Smarty templating engine for all PHP projects. It gives you an easy way to separate the logic from the presentation.

like image 40
rmeador Avatar answered Oct 22 '22 06:10

rmeador