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.
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 hear a lot about cakephp, it's even a requirement for some hiring companies on job boards. I'm a beginner programming but I like making things from scratch because I understand everything and it feel more flexible.
For my next project I want to build a site which has users, users can vote and they can post entries as well as manage their entries. Would cakephp be a good framework for this or should I just do it on my own?
I'm a great fan of CakePHP and, up until recently, I've used it for all of the projects I've worked on over the last four years, introducing it to two companies along the way. Now I'm working in Coldfusion so I don't use it at work, but I still do at home.
If you're just starting out then you don't need to worry about CakePHP as a job requisite just yet! Learn PHP as well as you can - get your hands dirty and do all the repetitive stuff like connecting to databases and building queries.
More important in a job application (and when developing using CakePHP or any framework) is to have a good knowledge of the underlying language, in this case PHP. Once you know it well you can make an informed decision about frameworks and MVC. Then you'll really see the advantages, whether it's Cake, Codeigniter or something built by the girl nextdoor.
CakePHP is an MVC framework that was built using the Ruby on Rails style of architecture. More than anything it gives you a convention that you can follow, and other developers can follow, that is well documented. If you build it yourself from scratch you may learn more about the underlying PHP APIs, but you'll lose out on the benefits (likely) of a commonly accepted design architecture.
I would suggest learning CakePHP or try out CodeIgniter instead. The idea is that you can quickly roll out an application with a very robust feature set, that is well tested, that doesn't require you to spend months building out the core components. It is more important that you are capable and efficient then specifically that you know one framework over the other.
CakePHP is a web framework for PHP implementing the Model-View-Controller (MVC) paradigm. It's designed to make PHP web development easier, but the overall workflow is completely different to that of plain PHP.
No-one here can tell you what works best for you, but I'd suggest learning to use PHP before learning to use CakePHP (just as the Ruby on Rails guide suggests learning Ruby before Rails). You won't need to, but it will help a lot.
Model-View-Controller (MVC) frameworks for other languages that you may be aware of and/or familiar with include Django for Python, Ruby on Rails for Ruby, and ASP.NET MVC for ASP.NET.
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 recently started working for a web firm as a freelancer, taking my hobby of coding in PHP to a career level, and since then I have been overwhelmed by the amount of work that needs to be done within short time frames.
The problem isn’t being able to do what is asked, but being able to do it all as quickly as is needed of me. I never used any PHP frameworks, but if I started using one, would that speed up the entire development process? If so, how drastically?
Also which framework would be best for my purpose?
If it matters, what I do is mostly build back end CMSs and tie that in with front end functionality for small business client sites.
Once you know a Framework well (i.e. don't have to spend time learning how to use it), yes, it helps speed up both :
The development process
The maintenance process
Why ? Well, probably, at least, because :
It provides guidelines
No need to think (too much) about what goes where, or how to do X or Y
Those guidelines are known by everyone who knows the framework -- which means you can hire a guy that knows the framework, and he'll need less time to be efficient on your project
It provides a lot of useful libraries
which means less time spent re-inventing the wheel
and components that are already integrated in/with the framework ; which makes it easier to use them from your application than some random external component
Now, for the "which framework should I use" part... it's mostly a matter of personnal preferences, and there are many existing questions about that on SO.
To only give you a few links, you can start taking a look at questions+answers such as :
PHP Framework Decision - Analysis paralysis!
What PHP framework would you choose for a new application and why?
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?
And there are many others -- you can use the search box, in the upper-right corner of the site, to find more ;-)
They certainly do.
Something to be aware of is there are variable learning curves depending on the framework that you decide upon. So you might experience slower development initially while getting comfortable in a new environment.
I have seen the zend framework recommended may times.
firstly if you go to phpframeworks you can view exactly what kind of framework would fit your work load.
next, frameworks initially take time to implement corectly, but once everything is done, it speeds up considerably your development time for your projects. However what's nice about this is that if your framework is done correctly you can apply it to all your projects. Where I work currently we have a framework that is implemented and it applies to all the sites that are being developed. if you want each project to have the same type of look and feel and functionality then a framework is your best bet
however if it's just for one project it might be a little too much.
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.