4 ms·
Ask HN: Thoughts on PHP frameworks?
I have only depended on a PHP framework once. I was just beginning my work in PHP and was looking to choose a framework with social networking features. The framework I chose ended up having a HUGE security hole and my site got hacked, thus setting off a downward spiral of my user rate. It literally killed the site.
I haven't used a framework since.
I have become complacent writing everything from scratch. I have a ton of PHP code that I reuse in a lot of my projects which saves me a lot of time. Scaffolding is a time saver too. Here are my pros and cons of each.
Pros
---------------
1. More secure. Your code isn't available for the world to see. If there is a hole, it will take a lot longer for an exploiter to find it.
2. You know every character of code...since you built the darn thing!
3. If you want to know how everything works, you don't have to look over some other dude's 10,000 lines of code.
Cons
---------------
1. Not as simple to code (most of the time)
2. Cool features specific to that framework have to be implemented by hand
What do you guys think? Am I too independent with my code?
- aDemoUzer 16y agoFor past 6 years, I have done the same thing as you. Coding everything on my own, and now have a file with 1.2K of line code containing the functions I have created over the years. Now (more like, since a week ago), I have started to use a template system. I am still writing most of the code myself, since the template is used to organize the code into in MVC manner. The site I am using it @ http://peri.me/2B1A/ http://peri.me/2B1A/ Even if you don't want to use a framework, there is no harm in using a template system. I use http://www.twig-project.org http://www.twig-project.org
- gambo 16y agoHi, Yii framework looks very promising to me: http://www.yiiframework.com/ http://www.yiiframework.com/ Which framework did you use?
- petervandijck 16y agoCodeIgniter is fairly decent. I'm using http://fuelphp.com/ http://fuelphp.com/ these days, which is similar but newer. I also go back and forth between framework and homegrown. I've done homegrown for years. Framework does have the advantage that you get to use a lot of code others spent time on, so I'm sticking with that for now. I dislike the Yii approach (it generates code based on your db). Don't think it's necessary, I have no problem coding and optimizing some mysql queries, no need to hide that behind a black box.
- damncabbage 16y agoAfter going through CodeIgniter, Zend Framework and CakePHP, I'm pretty much exclusively using Yii for my own projects these days. The way Components and Behaviours are used throughout the system makes it very easy to combine and plug in disparate modules of code, and it's the most Rails-y framework I've found so far (barring CakePHP which appears to have come leaps and bounds in the last couple of years since I used it last). (In summary, it matches how I want to work. :) Keep looking until you find something that does the same for you.)
- obviator 16y agoI have used Symfony for my last few projects. I'm happy with the way the framework is designed, and it's quite longstanding. Another benefit is the templating is done using pure PHP, so you don't have to learn a new templating language for loops, etc. A new version (v2.0) is due to come out later this year. The introductory documentation and tutorial are excellent. The Jobeet tutorial walks you through how to create an entire application, with the Symfony developers' best practices being implemented right from the start. Only con: I do have trouble at times finding answers to the obscure questions I have. There seem to be a lot of forum threads about Symfony, but not quite so many answers. If you can find an experienced Symfony developer, I highly recommend talking to them and getting a few pointers in the right direction. That said, I think it's a great framework, a little on the old side in terms of style, but still quite flexible.
- komlenic 16y agoThe tradeoff is control vs speed/efficiency. Generally, I agree with you (and prefer to just rely on my own function library), but for the most part this is for somewhat dogmatic reasons like "you know every character of code..." etc. While those things may be true, they don't necessarily make my code any more secure, bug-free, or well-written. Recognize that any popular framework has had a lot of eyes on it and any pain/problems with it will have been fixed. The idea that you know every character of code and therefor have more "control", is not entirely accurate and probably misses the point.
- bo_Olean 16y agoHere's what i would like to say on your pros and cons list. P: 1. open source code is exposed to the whole bunch of users doesn't necessarily mean the code will end up unsecured, let's take it as we get lots of contributor around to find and patch those security holes. 2. once you get working with PHP frameworks understanding the code will be easy. 3. why not bother looking at the framework code if you get benefits on every work onwards? C: 1. Most of the frameworks follow MVC separation, understanding that takes time, once you get the idea, writing code and using your existing code as plugins/libraries to the framework will be super easy. 2. The whole community is contributing, it will just take few posts in community forums or few minutes of googling to find the feature you are looking for. if you ended up coding the feature yourself, give it back to community. that is how you become part of the community and how the frameworks grow. In situation when you need to hire someone to work on your codebase, use of available opensource frameworks will save a lot. i will suggest any one of these frameworks to work with: https://github.com/tylerhall/simple-php-framework https://github.com/tylerhall/simple-php-framework (structured code) http://codeigniter.com http://codeigniter.com (easy to start with, very good documentation) http://www.symfony-project.org/ http://www.symfony-project.org/ (nice documentation yet steep learning curve, once you get it as easy as CodeIgniter) i personally appreciate your approach too, that is a lot of effort you put there, but if you don't feel like using frameworks such as Symfony/CodeIgniter etc.. at least you may want to workout your code in the MVC or HMVC structure.
- vantran 16y agoI used to be like you, not using a framework for exactly the same reasons: I wrote everything myself, and since it's PHP, it wasn't that hard. I knew how to exactly when something was going wrong, I didn't have that power of clarity when I was using a framework. But over time I've learnt the following lessons: 1. I was naive to think that my code would be better than the code of an established frameworks that have undergone through extensive testing by a big community. 2. It's a lot harder to bring people on board to help with coding. I can navigate my code very easily, but many people who are used to how to do things in a framework found it very hard. 3. Without the help of a community, I had to code EVERYTHING myself. There is no gem or plugin to install, which will REALLY help speed things along. In a startup environment, speed is a real competitive advantage, every bit of speed you can gain over your competitor should be pursued. I can't stress this enough. 4. When you run into serious problems, Google search is unlikely to help if you don't use a framework. You're likely the only one with that problem. Whereas if you use a framework, there's a very high chance other people have run into the problem before, and the error thrown out will be in a Stack Overflow or a bug tracker somewhere. Your life will be much easier when trying to track down serious bugs. I used to use PHP for about 5 years, and I think the problem with PHP and frameworks is that there are so many frameworks around, and we just don't know which one are the one to use. So many developers have this question. Code Igniter or Kohana or CakePHP or... 20 other frameworks out there? It really sucks when you have to put in the time to figure out which frameworks work for you, and it's one of the reasons why people don't use a framework in the first place. Where as for Python, Django is a clear winner and Ruby, there's RoR. Those languages have many other frameworks too, but they have a clear winner with a large community who could help you. As for me? I'm now doing almost everything in Ruby and Rails, and not looking back. I feel very good about the way I work now. I have become as good with Rails as I was with my own code, and it only took a few months. I suggest you give it another try. It will be time consuming at first, but it's very worthwhile in the long run.