3

I've recently come on board with a PHP application. There has not been much design put into the app - there is a front controller, however, view, model and controller code is usually mixed together.

I would like to slowly start refactoring the code beginning with moving all the SQL queries into appropriate models. Having looked at a few frameworks, it seems that most frameworks are setup with the assumption that an app will be developed from scratch using that framework.

Is there a good framework that I can just kind of plug-in so that I can use the model libraries and then perhaps later on, integrate more of the app into the framework? Would Doctrine be a good tool for something like this? Or should I just setup my own models without relying on third-party libraries?

4 Answers 4

4

If you have an existing php application, then there is no point to migrate it to some framework. Frameworks help you to develop project faster - you already have one. At this point adding framework on top of what you have will only make your application more complex and, most likely, slower.

Instead of trying to find some magical framework, you should invest in refactoring (apply some OOP principles, like SOLID) and documenting the existing code. Maybe start incrementally add some unit-tests.


P.S. Doctrine is an ORM ( 1.x implements activerectord , 2.x - something like a datamapper ). ORMs are for people who are extremely lazy, misguided or do not understand SQL. By moving your existing SQL queries to ORMs code you will make it all only slower. Additionally, you will encounter problems when migrating complicated queries. Just dont do it.

5
  • I guess the reason for looking into a framework is that the other developers who have coded this site have not thought much about design. I thought a framework might help to enforce coding standards as well. It might be better just to develop classes as I go along and refactor. Oct 13, 2011 at 19:05
  • @MattMcCormick , framework might enforce some structure, but you should not look up to php frameworks for good standards or practices. They all are flawed. Usually its the case of choosing the lesser evil. Instead you should read stuff written by Martin Fowler, Robert C. Martin and Misko Hevery. You could start by watching the "Clean Code Talks" series on youtube.
    – tereško
    Oct 13, 2011 at 19:45
  • orm's are good for people who are extremely lazy. (this can be translated as people who like to fix less errors in their code, and do less repetitive coding of simple sql). granted orm is not a be all and end all solution for replacing sql, but in some instances it can save a lot of time coding an application, i don't use orm all the time but definitely in some instances it is invaluable
    – bumperbox
    Oct 18, 2011 at 3:22
  • @bumperbox , i too will be lazy and just refer you a comment i wrote few days ago.
    – tereško
    Oct 18, 2011 at 4:28
  • @teresko i happily agree with your points, i just don't agree with your comment. "ORMs are for people who are extremely lazy, misguided or do not understand SQL." I am not extremely lazy, i don't consider myself misguided, and i know sql inside out, yet i choose to use orm when it is the best solution for the job :)
    – bumperbox
    Oct 18, 2011 at 5:27
1

I've just started rewriting a site in Kohana, and I'm quite happy with it. It seems flexible and powerful. It's very similar to CodeIgniter, but a little more modern (more of the latest PHP features are used).

1
  • 1+ for kohana. i have now converted a number of sites that had no framework to kohana and it has simplified the codebase massively. kohana is a configuration by convention style framework, but does have the ability to override all the conventions when required. it fits in well with existing code, and i have been able to replace parts of sites at a time, rather then an entire rewrite and relaunch
    – bumperbox
    Oct 18, 2011 at 3:26
0

If you want only MVC (not HMVC or more difficult) frameworks for simple adoptation with existing application you should touch CodeIgniter. ActiveRecords is very easy for refactoring from existing sql-queries. You even can use default or hand made functions or classes for building queries in its models.

But default, Codeigniter isn't enough flexible for difficult or multi-namespacing applications.

0

Im migrating a site using Zend and Doctrine2. The site wasn't OOP in any sense but it was divided between logic view and dal. The migration is still in process (new features are coded with framework, existing feature gets migrated only when big changes are needed).

Both frameworks are non intrusive, and the most valuable thing you get for me is to standarize things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.