views:

224

answers:

7

Hi,

I've recently inherited a medium-sized php site which is horribly coded. It violates every best-practices methodology, from MVC to DRY, is vulnerable to SQL-injection and everything in between.

I've visited the other questions and already put everything on a VCS and am considering the framework alternatives. However I'd like your opinions on a framework that lets me slowly migrate from the actual site to a framework controlled one.

Thanks.

+4  A: 

I will put my vote in for CakePHP (http://www.cakephp.org). It has the ability to manage everything very nicely.

Template

This will allow you to create the base template / layout for the site. It is the main body of the site. You can store multiple layouts all in the views/layouts directory. You can identify what layout you want to use for any given page within the site.

Static Content

If you have static content pages, they all reside in views/pages. These will load into the layout wherever you put the <?php echo $content_for_layout; ?>.

Custom Code

Many times, you will have custom code that may not fit in the framework. No worries, you can add this to the libs or vendors folders and call the functionality from there.

Speedy Upgrade Via Bake

One of the cool features of cake is the bake feature. Once you have added your schema to the database, you can use bake to have CakePHP write all of the models (with relationships), the controllers (with basic CRUD and admin sections), and the views for each action within the controller.

Cake has been a great fit for all of the projects I have worked on. It keeps the code well organized, has a very active community, and their documentation is very well written and understandable.

UPDATE: For additional information about some sites who use cakephp you can see a sample list here: http://book.cakephp.org/view/510/Sites-in-the-wild

A few notable (high traffic sites) would be:

https://addons.mozilla.org

http://scratch.mit.edu/

cdburgess
Use CakePHP if you like a framework that craps all over the global namespace, with APIs that change frequently, and has an unnecessary large footprint.
stillstanding
Not sure what you mean by "craps all over the global namespace". But yeah, the APIs change as all of the new features are added and updated. But they keep it well documented. But you do not need to upgrade your version of cake if you do not want to. And yeah, if you are running legacy hardware, you may have a problem running much of anything. I know they have projects at Yahoo running cake on pentium d boxes, managing 30mil+ keywords on Google and YSM and it runs great. So I am not sure what experience you are speaking from but it's not true for me.
cdburgess
+1  A: 

This sounds like a massive undertaking.

I can only recommend CakePHP because that is what I use, but that does not mean another framework would be less or more suitable. They're all pretty much the same when it boils down to it.

Choose on whatever criteria you wish, such as public support/user base (Cake's is massive), feel, name, colours on the webpage, whatever. But my advice is to stick with that choice and ride the learning curve.

Leo
+2  A: 

Take a look at Fat-Free Framework. It allows both procedural and OOP code, so you can have a two-stage approach. If the base code is currently procedural, then you can focus all efforts first on transformation to MVC architecture. That way you can have a proof of concept that all future efforts can be as fruitful as the first phase. Then you can move too strictly-OOP. No other framework will give you this kind of flexibility. And your end-users will not feel any delays, or worse, a culture shock.

stillstanding
CakePHP allows for this. Just drop everything into webroot the way it is and it will run just fine without processing through the framework at all. As you migrate pieces to the framework, you just update tje link they point to. So for example instead of running `add_user.php` once it has been migrated, you update the link to `/user/add/` and the framework will kick in. The downside to using something like Fat-Free is the loose enforcement of structure. It doesn't eliminate bad coding practices, but rather encourages them if someone cannot handle the OOP structure.
cdburgess
non-enforcement does not necessarily mean encouragement. a stupid coder can always trained to be a smart coder. a lazy coder will always be a lazy coder.
stillstanding
+4  A: 

Zend Framework would actually be the best choice in my opinion, as it has a great use-at-will structure and it is no full-stack framework like most of the others.

That means that you can start with migrating the model-layer first without having to touch the view or controller part. And even when it comes to the controller part, you could first put everything into controllers without having to rely on the router, so you could still use your old URLs.

DASPRiD
Ended up going with Zend, been very happy with it until now. The docs are great and I even reimplemented the search on Zend_Search_Lucene
Jeduan Cornejo
+2  A: 

You will get as many answers as framework users there are in this place. It's obvious that someone using framework of his choice will advice it to the others.

I opt for symfony.

However, if you care about best practices than both symfony and Zend are a good (and only) choice.

kuba
+3  A: 

Zend Framework is awesome.

Even better, this excellent post from Chris Abernethy shows how to gradually migrate an existing site from a twisted plate of pasta into a nice MVC structure using ZF.

David Weinraub
+3  A: 

Kohana is my framework of choice, but I won't start to wax about its good points, I'm sure it can do anything the others can do.

Faced with the same legacy codebase problem as you described, my response was to take Kohana and disable the request routing, so that you can just use it as an include on a page-by-page basis until you're ready.

The changes are minimal; if you're interested the fork of kohana is up on github

You may need to adjust the php error level settings depending on the kludgey-ness of your codebase ;)

Lethargy