There are several questions about PHP frameworks, but I'm curious as to which one(s) are used in the commercial world when developing web applications with PHP. At my first web-based job, they didn't have a framework for the PHP codebase. Is this common when dealing with PHP? If not, what frameworks to companies producing a product (either a site that provides a service of some kind or a web-based product that can be purchased) using PHP tend to use?
Is this common when dealing with PHP?
In my experience, unfortunately it is. This is of course a gross generalization, but people who tend to learn PHP as their first programming language don't learn the essentials of maintainable software development and often don't really know how to write good code. I think this is a failing of the PHP community, where historically most learning resources don't emphasize good practices (probably because the authors didn't know any better!). You can of course write good code with PHP, as long as you understand underlying programming principles.
Companies will often start out with a hap-hazzard code base of PHP scripts that get re-used and gradually extended from project to project (often without source control!). The companies that know what they're doing and take it seriously will evolve this into some kind of in-house framework, or I have often found they'll move onto something without the historical crapness of PHP, like Django or Ruby on Rails.
If you're just starting out, there are several decent MVC frameworks that will form a good base for all your developers to learn and use. In no particular order:
CakePHP
CodeIgniter
Zend Framework
There are of course others as well.
That said, as always it depends on the project. Sometimes a framework either won't make sense or will be overkill, othertimes you're better off using a pre-built product (like a CMS) and building extensions to it.
Most frameworks are strongly focused on the presentation layer. Now, "corporate" is of course a rather vague term, but I assume you mean for more typical IT tasks, such as accounting, CRM etc. For these tasks, the presentation layer is a much smaller part of the entire application. Not only does this make said frameworks less important - it actually disqualifies them somewhat, since you don't want the restrictions on your model layer, that they impose.
I think it gets more and more common to use a framework. A few years back most programmers developed their own framework. But the cost to train a new employee for such a framework gets higher and higher. Therefore many companies are moving now to well known frameworks.
I guess that Zend is currently the most used Framework in the corporate environment. One reason is that it does not give you any restrictions on the model layer.
I can not predict the future but I guess that Flow3 will be used in the future too. It is the new Framework behind Typo3. And many Typo3 developers (web designers) who need to write web applications will probably use Flow3 then.
In last two three places I've worked the company had their own (private, built in-house) framework.
According to a PHP Framework Popularity at Work survey by Sitepoint in 2015 (7554 survey participants) the five most used frameworks are
Laravel (22%)
Symfony2 (14%)
Nette (9%)
CodeIgniter (8%)
Yii 2 (7%)
Furthermore survey results indicate, that
5% use a company internal framework,
3% use no framework at all,
3% use a CMS for everything,
1% use a simple MVC framework.
There seem to be continent specific framework preferences: In America and Asia, Laravel seems to be the framework of choice (except for Russia: Yii 2), whereas in Europe you'll find more Symfony2.
(Be aware that this is just referenced from one source -- see links above.)
The only enterprise-level framework I can think is Zend Framework. CakePHP, Code Igniter and others are only focused on RAD development.
Having experience with CI , yiiframework and calephp (not much, really) my opinion is that CI is not flexible as ohter 2, so I do not recommend it on larger-scale projects.
Anyone who disagree, just can try a demo project with cakephp and Yii and he will see how things are easier with them as crud,form validation etc.
Of course all have their disadvantages :)
recently i talked with a CTO of a company, offering a e-lecture solution and we talked about PHP for a while ... we both agreed, it is not the best language for rock solid solutions, but he pointed out the symfony framework, they used just before moving to java ...
also, flow3 mentioned by raffael is quite powerful ... most interesting thing to me is, it brings AOP into PHP ...
greetz
back2dos
You may want to look at www.flow3.org, it's a pretty comprehensive approach to PHP application frameworking and is rapidly approaching its first mainstream Beta release.
I'm not sure if PHP has gone into the enterprise market in the US yet but when i worked in a corporate office the language what they use is Microsoft .NET.
PHP is yet to enter the corporate world IMO. It is popular with the hacker world and maybe micro and small software/web companies.
Related
I'm about to develop a web app (PHP/MySQL). I prefer to use the MVC style when developing apps, but I've always struggled writing my own MVC framework in the past so I've started playing with CodeIgniter. After a couple of tutorials I better understand how to properly develop with a MVC framework and I'm totally comfortable using CodeIgniter to write my app.
The thing is I'm now wondering if its better to write my own MVC framework for this app or use CodeIgniter? My worries are due to the fact that I'm just getting this app written to serve as a prototype and will hand it off to more experienced developers down the road. I'm worried CodeIgniter has limitations that I'm unaware of yet and could hinder further development for me or the next developer(s). I'd imagine its easier to get around issues/limitations of a custom framework than it is of a 3rd party/ready made/stock framework.
Any insight?
There aren't any real limitations to CodeIgniter as most of the core can be extended. I have been using it for years and not found anything I couldn't use it for.
Kohana is a little more fun if you're into PHP5/OOP stuff but the lack of documentation will make learning it quickly rather difficult, especially if you are being paid to produce this.
Use CI, it will speed you up plenty.
I'd would go with CodeIgniter if you're familiar with it (and not writing your own framework from scratch), the app is a prototype, and it's getting handed off to more experienced developers down the line.
CodeIgniter isn't an obscure framework, it's pretty widely used and well documented. If your developers kick up a fuss, then they're probably aren't as experienced as they would like to think they are.
For a prototype I would say definitely use whatever you're familiar with, instead of making the project much bigger than it needs to be. Writing your own framework is a huge challenge, but it's also a really good learning experience. I've written my own suited to my own needs just so that I could learn the language "in the deep end" (and I keep adding to it whenever I use it... maybe someday, when I decide it's "fully featured", I'll release it into the wider world). But you should only do that if you've got the time, and plenty of room for everything to go wrong.
Well, the question is: can you do better than every other MVC PHP framework out there? Reinventing the wheel only costs more time and the focus off your application changes, because you have 2 seperate things to maintain.
I would stick with a proper MVC framework. We use Symfony exclusively for that use. It's a great framework with a lot of features borrowed from other frameworks and other programming languages. However, the list is endlessly for PHP framework. I recommend reading a bit about other frameworks and pick the one which is the most suitable for your needs. It saves you time in the end.
As a developer, I had to go through the same road.
Personally, I chose CodeIgniter as primary tool of my development, mainly because of community support and straightforward MVC. However, CodeIgniter was built by EllisLab, and they are not community driven. If you are looking for something that has more dynamic, community driven, open source MVC framework, I would suggest using Kohana.
Kohana has a good community, and they have some notable contributors. Check it out here
If you are thinking of choosing from different types of frameworks, I would suggest make a list of things you want out of a framework, and do your search based on that.
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 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.
I have a simple site to develop and would like to learn PHP as I go. I want the site to be secure, scalable, and easy to maintain. Should I learn a framework and PHP simultaneously? If I build off of a framework there will be lots of unfamiliar code in play. Would you say this increases security risks?
There's nothing about using a framework that will impede you learning PHP, and using an established framework will reduce the security risk, as you'll be dealing with well tested code for handling common tasks.
At the core of most of the PHP frameworks in play these days is this simple three step workflow
The URL is requested and routed through a central bootstrap index.php file
The URL name is used to derive a classname and a method name (and action method). This is your main entry point and where you start writing PHP to handle the request
At the end of this method, control is handed over to a view template, which has access to certain values you set in step two.
Pick a framework, learn how it does the above, and then write any kind of PHP you want in the action method and the view template.
Yes, there will be a lot of other PHP framework code in play, but you never have to look at it.
Yes, the framework will have a multitude of features and/or a "preferred" way for handling things, but you only need to use those you instantly understand.
When you start noticing patterns of ugly, boring, or insecure code, take a look at the framework features again. More often than not after "doing it wrong" you'll get insights as to why the framework code did something in a particular way and you'll be happy to hand off the responsibility (I'd say ActiveRecord style models vs. SQL code is a big one here)
As you start using the objet oriented systems the framework provides you'll start to get interested in how they're doing certain things, and then you can start poking at the core framework code.
Absolutely. Frameworks will do all the boilerplate code for you, providing you a higher level of abstraction. It will probably be easier for you to code without dealing with some of PHP's idiosyncrasies.
Any half decent framework will also address security issues, so if you are new to the language, chances are your app written on the framework will be safer than the one you write from scratch.
I wouldn't recommend starting with a framework to beginning developers. If you've got a lot of experience with other OOP languages, there shouldn't be a problem. But you should at least know the basics (syntax e.g.) before even thinking about using frameworks.
I would say it depends on your prior experience. It's not so much PHP itself, but the web server environment it lives in that can be distracting. If you're already familiar with the HTTP request lifecycle and have written web applications in a similar stateless fashion as you do with PHP, you shouldn't have a big problem jumping right into using a framework.
If you come from a "stateful" background or no background at all though, the abstractions a framework offers can become a problem. You should at least know how to handle sessions, cookies, headers, $_POST and the like in plain PHP before having the details abstracted away from you by a framework. Also see this previous answer of mine.
I think minimising the amount of custom code you are writing is probably a good thing if you are not confident in your ability to create secure systems (particularly for things like authentication). As a result, I think using a web framework in this way would be to your advantage. It will also allow you to familiarise yourself with the core of the langauge without worrying about peripheral concerns.
I have seen a few people (with a big previous OOP knowledge) to learn PHP and symfony simultaneously without difficulties.
In fact, moving from PHP from an object oriented language is just learn a few conceptual things and the syntax and API of PHP itself.
In my opinion, there's nothing wrong with learning a framework at the same time as you are learning a language. There are already a fair amount of situations where this is the case by necessity. For example, most people learning Objective-C learn the Cocoa frameworks at the same time, most C# programmers will learn .Net along with it, even the JDK should be considered a framework which you learn along with the Java language. And for what it's worth, I learned the Symfony framework with very little PHP experience beforehand.
I would advice you to start with PHP turorial on w3schools.com. It is short and clear. You can learn all the necessary basics in one-two hours. In order to understand any framework you will need that. Then study the first and the second chapter from CakePHP cookbook and create your first CakePHP applications using their tutorials. On the rest I agree with Alan Storm.
Getting started with a framework in PHP, also depends on the fact whether you have some prior programming experience and if yes, what kind of.
If you have muddled in some other programming languages like java, c, learning a php framework simultaneously while creating your website might not be too difficult.
Almost all of the PHP frameworks you will encounter use the MVC design pattern - if you understand the basics of MVC, if you have implemented or have gist of design patterns in other programming languages, then it will be quite easy starting with PHP frameworks.
Also your choice of PHP framework will be the deciding factor. If you employ PHP frameworks like Codeigniter, Yii, maybe even CakePHP which have comparatively smaller learning curves, you will find your path wellpaved for you in PHP. Although if choose some framework like Symfony, Zend - you might get frustrated in taking too much time in doing simple things, in turn blowing up your project.
As for the part about security risk, all of the frameworks I mentioned above and some others I have not mentioned, have spent enough time on the stage to have squashed the security risks.
Hope this helps in deciding.
Although I'm a fan of frameworks, I agree with some of the other comments above. Starting with a framework can be pretty confusing, especially if you're not experienced in the theory of Model View Controller (MVC) object oriented programming (OOP).
Truth be told, I've seen a lot more unfinished framework projects in my day than apps built without a framework. If your application is written with some clunky PHP and the application takes off, then you can hire the necessary resources to move to a framework and get it developed to withstand a lot of usage and utilize resources effectively.
My advice would be to master PHP first, then move to frameworks. My last note on this, many frameworks have flaws as well - so depending on your application needs, applying the wrong framework could drive it into the ground.
Just my 2 cents as a guy that has released a couple of enterprise apps successfully - without using a PHP framework.
I have been dabbling in programming/scripting languages since I was a kid. I started off with HTML and CSS, then went on to PHP (which I got quite good at) and then to Python, Perl, and C(++). I've recently done a lot of work in PHP (along with MySQL).
After spending so much time learning these languages, I now want to do something with them. I'm looking at starting/contributing to an open source project; almost certainly a web application of some sort.
In my experience with writing (admittedly small) web applications, I've found writing "pure" PHP to be an extremely slow and tedious process.
My question is this: if I were to be writing a relatively complex/large web application from scratch, what should I write it in? Should I use pure PHP/MySQL, or use a framework like Django, Rails, or CakePHP?
Writing a complex application from scratch, I would definitly not use "bare PHP" : I would certainly use a framework : they provide :
a large number of useful classes/methods
some set of rules -- like "in which directory should controllers be saved", "how to write a view", ...
MVC -- i.e. they help with better structuration of the project
Note that this answer is valid for both personnal projects, and professionnal projects.
There are several great Frameworks in PHP, like :
Zend Framework
Symfony
CakePHP
Code Igniter
Kohana
One thing to remember : learning how to use a framework well will take some time : starting with a small project, before going for a big one, would probably be a good idea ;-)
Now, when you're asking yourself the question of "which framework should I choose", it's mostly a matter of personnal preferences... And here are a couple of questions/answers that might help a bit :
PHP Framework Decision - Analysis paralysis!
To use a PHP framework or not?
PHP - MVC framework?
Which PHP Framework is right for this project?
Best PHP framework for an experienced PHP developer?
As you're asking me which Framework I would choose ; well :
I really like Zend Framework, and often use Doctrine as ORM (it's the default ORM of Symfony, but can be used very easily with ZF)
If I had to choose another one, I would probably go with Symfony, as I've seen it used on a couple of projects at work, and know many people who work with it and like it
If you already know that language, you should most definitely use a framework (unless you're a masochist).
For me, besides that fact that they're usually bundled with all sorts of great libraries, using a framework is all about using time effectively.
Most importantly, it will save you time. You're freed from the nitty-gritty of worrying about the foundation/architecture and are able to spend your time of the features of the application itself.
Also, it will save others time; especially since you plan on being all open sourcey.
depending of your skills level, yes you can do it in pure PHP without frameworks. This also will be good, IMO, to improve your skills at debugging, logics, and others. But, on the other hand, you will restrict to other programmers to improve/maintain your code due to learning curve, in this case, the framework serves as a commom language. I recommend that if your project will be complex, or with the possiblity to other programmers join in the project, that you choose a framework which you feels comfortable and use it.
Depends on who will be working with the code, on which plattform it has to run and how complex the database should be.
If you develop for a company or community it is always easiest to use PHP because there are many others who know it so i.e. for companies it's easier to recruit someone who knows the language.
If you mostly want to develop on your own, use what you like most, i even heard of websites written in pure common lisp.
If the application can run on windows only C# is also a good solution as you can develop web applications extremely fast and the .NET library makes many tasks easy.
As database backend you can use MySQL if the structure is simple but for more complex databases i'd use postgres as the MySQL performance seems to drop fast with increasing complexity (subjective opinion).
EDIT:
As others noted, Frameworks are always a good idea. There are web frameworks for most of the current languages. For PHP CakePHP was recently recommended to me.
We are currently looking joining an open source PHP farmework project instead of continuing to work on our own PHP MVC code. Likely candidates are Yii and Solar, because they appeal to our own coding style, have tackled issues that we feel need tackling.
I realize there are plenty of PHP frameowrk related questions on SO already. However, I'm having a really hard time finding people that actually use one of these (esp. Solar) in a real world environment.
So, my question: did anyone work a real life project with one of these? How did it work out for you? What were the major issues?
I'm not looking for benchmarks or excitement about the theories behind each of these. It's clear that their creators of both frameworks did a tremendous job. What I want to know is:
did you use it?
did you like it?
pro's and cons based on real world use?
I use Solar daily for internal applications at work and personal projects at home. It is a top-notch, solid framework that I can highly recommend to anyone. It is in beta3, but stable should be coming along in the next couple of months.
A common criticism is the lack of documentation. I am happy to say that that is changing rapidly. New documentation is being written daily. In fact, two new chapters are already up.
A great way to get involved in Solar, or to get questions answered is to visit the IRC channel #solar-talk on freenode, or join the Solar Talk mailing list.
Visit the Solar website for all the info.
I can't comment on Solar or Yii because I've never used them. When I've given both a cursory look, they did not seem as stable as frameworks I've used before. I've developed with CakePHP for years and have run into the PHP 4 barrier with it, where continuing to develop for PHP 4 does not make sense any longer. Ultimately, it just costs more money.
If you are looking for a framework to build upon, I would recommend looking into the following:
Zend Framework
Lithium
All are very modular by nature (including Solar and Yii), with support for integrating excellent tools like the Doctrine ORM. Some assume Doctrine is your ORM of choice. Honestly, it should be.
ZF is decidedly PHP5 only, which I like. I also appreciate the modularity of it. I can create a base "project" and then add individual "apps" to it, each with their own models/views/controllers. You can also use its classes/features individually without the entire framework bootstrapping process. It is backed by Zend, and is very mature -- I'm assuming because so many trained eyes have used and improved it. The consequences of this are fantastic: just browse through the web site, follow the quick start and look at the available components in the reference guide and you'll see what I mean.
Lithium was forked off from CakePHP's Cake3 project, aiming for a framework with support only for PHP 5.3 and PHP 6. It is decidedly PHP 5.3 only, which means it has hitched its wagon to the newest stable PHP with the most features, such as anonymous functions, a native MySQL driver, and much more. Worth looking into if you are able to move your team to a PHP 5.3-only environment, especially if you have people who know the value of more modern programming techniques found in languages like Python or Ruby. It is a young framework, but has much of the same talent behind it that CakePHP has had, so that gives it a huge thumbs up in my book.
I've used Yii a bit now and have found that it's worked quite well for me. The main con against it is that it's still relatively new and most people haven't heard about it.
That said though, if you were to pick it up as your main framework, that would help it become better known and you might even consider helping Qiang with some development work.
Just when you are deciding, make sure you've had a look through the issues list to make sure that you are aware of what the current bugs are, and what the upcoming features/changes will be.
I can't comment at all on Solar.
I've worked for a handful of digital and new media design agencies in the North East of England for a couple of years now and have yet to come across an instance of the development team using a framework.
Most web design and development agencies these days favour creating their own framework or CMS; I guess it's a form of validation for them. They don't feel they're worth their salt unless they can develop their own systems and solutions from scratch. Hell, I'm the same and have build my own CMS!
The advantage of using an existing framework is that development time is reduced as commonly-used libraries and helpers are already pre-built and ready to be implemented. However, the use of a framework can easily become a con if the framework used isn't commonly known.
So for instance, if you use an obscure framework like Solar that not many developers are familiar with, any other developers working on your sites are going to have an additional learning curve, which in turn increases development time; the opposite of the desired effect.
Hope this helps you. Commonly-used PHP frameworks out there at the moment include CodeIgniter and CakePHP.