开发者

What kind of projects are PHP frameworks suitable for?

开发者 https://www.devze.com 2023-01-10 11:40 出处:网络
I\'m building a site like SO using PHP as a personal project. I started out with writing flat PHP files (the kind with SQL queries mixed in with HTML). After doing a few pages I noticed that it was ge

I'm building a site like SO using PHP as a personal project. I started out with writing flat PHP files (the kind with SQL queries mixed in with HTML). After doing a few pages I noticed that it was getting hard to maintain. So I started using an ORM (Propel). Then I got introduced to Symfony.

I started refactoring my code to fit in with Symfony's MVC pattern. To me, it seems that for a small project such as this Symfony actually makes things more complicated and I actually develop slower. Are frameworks more geared towards开发者_StackOverflow社区 large applications designed by multiple teams? Or am I doing something wrong?


Any framework or new technology will have a learning curve during which you will seem to go slower. If you follow the MVC pattern and best practices for your framework, you will generally end up with cleaner, more maintainable code. There is some overhead to MVC and to getting things structured well. This overhead will payoff more for larger projects, projects that last longer (lifespan of the site as well as development time), and for projects with more developers. For small sites that will not be maintained, the overhead can be too large to be worthwhile.

If you're going to write PHP professionally, or you intend to write seriously, your time is well spent learning a popular framework or two.

Also, in no way is "a site like SO" a "small project."


It depends upon the framework and how much you wish to trade off ease of development in the future with speed of development in the present. The best way to get to the bottom of it is to try out a few frameworks and see what suits you best. A few random examples include:

  • Agavi
  • Kohana
  • Zend Framework
  • CakePHP

I have used all of the above and I personally found Agavi to be the best, although certainly not the quickest to work with. I was not so impressed with Cake as the rest, but again this is personal preference.


I don't know how "small" your project really is, but even though it takes time to learn a framework and design your project so that it follows the framework's philosophy it's usually worth it.

In my experience, when projects start to grow like your project apparently does (naïve PHP → factoring out the model → ...) you end up, in the best case, with code very similar to a simple framework. When you are using a framework on the other hand, the basic design of your project is usually really well thought-out, so even if you are not an experienced software architect (maybe you are?) you will get a good foundation for your project.

Also, you say that it is a personal project so I guess it's some kind of hobby or educational thing. Using a framework can be a nice way to learn about design patterns and best practices in web development.

Perhaps Symfony is not the best choice for you. I guess it's a matter of personal opinion in the end. Personally I like CakePHP when coding PHP and Django when coding in Python.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号