tags:

views:

595

answers:

3

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.

+9  A: 

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.

Bill Karwin
I am sorry, but that article absolutely sucks.
+1 - It's hard to argue against the creator of the language.
Bill the Lizard
+1 I too find many MVC Frameworks too bloated ("look at our Hello World example... it only takes 11 files!").
cletus
+2  A: 

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

rmeador
A: 

Have a look at this SO question and the answer. It's a pretty good, simple MVC design with some tips on how it can be improved. If you are concerned about maintenance, then at the very least you need to seperate presentation from logic (you need a view and controller). Smarty forces that, but it is a type of framework and you'll have additional syntax to learn.

Before you jump on Rasmus' "no framework php mvc framework" bandwagon, read some of the critical comments. Any web application structure is a framework, and Rasmus' approach isn't the best I've seen.

rick
Can you give an example of one that *is* among the best framework you've seen? I'm not disputing you, I'm just interested.
Bill Karwin
For php, Kohana best fits my philosophy. Most of the Zend Framework components are useful and easily used within Kohana.
rick
Rasmus' framework has a number of problems imo: - Little abstraction (no front controller, no inheritance) - No routing- Spagetti code controller- Needless code in the views (includes, heredoc, $s = $i%2;)- Functions returning html- Not portable using pecl and apc cache- global var
rick
I wish I could respond to your edit Bill. Rasums may have intended php to be procedural, but php 5 is a flexible dynamic oop language.
rick
Ok, thanks for the clarification. I think the example in Rasmus' article is a proof of concept and definitely needs some cleanup. But I think it addresses some performance criticisms of PHP frameworks vis. loading so many classes.
Bill Karwin
Btw, I was the project lead on the Zend Framework through its 1.0 release. So I'm familiar with the OO capabilities of PHP, both the good and the bad.
Bill Karwin
Bill, I didn't know you were involved in the Zend Framework. That's a well engineered collection of components. I agree regarding the number of loaded classes. Often, a few classes including a dispatcher, autoloader, controller and view object are enough. Sprinkle on components as necessary.
rick