Ive never heard of this before, and I have been coding in PHP for quite some time. I actually feel kind of stupid asking this question but, what is a PHP Framework? How can it help me? and how do I use one?
A framework in general is a collection of classes and functions that let you accomplish your goal faster in development. PHP Frameworks such as Symfony, CakePHP, and Zend all have a series of utility classes, tools, and structured elements that let you avoid reinventing the wheel.
Zend Framework, like many, has a strong MVC engine that let's you avoid rebuilding that functionality yourself.
To start using a framework, you download the framework itself. In the case of Zend, I download it, unpack it to lib/, and I'm good to go. From there, you just read the documentation on that particular framework to learn how to actually utilize the tools they provide. What functions to use, what classes where, and so on.
A framework is a big library. Exactly where the two differs, is rather fuzzy, but generally frameworks have stronger implications on workflow than libraries do. A (good) library is passive, where a framework is expected to be more involved. Consequently, frameworks are also often quite monolithic (eg. you can't usually use two frameworks together).
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 not sure if this is possible, but let's say you want to build a CMS, but you're torn between 2 frameworks because each has some features that you like. Is it possible to create the CMS with both framewoks? Does this approach have merits or pitfalls?
Speaking strictly about the Zend Framework (ZF) I would say yes. ZF components are written to be as independent from other components as possible. I would say that it would not be very difficult (It may actually be quite common) to integrate libraries of ZF into other frameworks like Cake, Symfony, or Codeigniter.
Is it possible to create the CMS with both framewoks?
While it's possible to use components from the Zend Framework inside other Frameworks / CMSs - this may be the case with other component libraries as well, but Zend's the most modular one that I know - It's usually not a good idea to mix two full-blown Frameworks.
Many central functions like MVC structures, URL routing, the database layer, Unit testing, error management and so on are by nature unable to be served by two frameworks at once without massive friction. Also, you're likely to get problems when one of the frameworks needs to be updated.
I would recommend to pick the framework that covers most of what you need, and try and add the missing features using plug-ins or own modifications.
Your question is too abstract.
For instance Zend Framework is more to be a library of specific functionalities ready-to-be-include into Your codebase then some closed development environment like for instance Symfony framework.
Thanks to it can be ZF simply included into your codebase (and Symfony too).
Symfony Framework compared to it is closed solution depending on front server environment so you cannot use it like some other framewor's slave.
It would really depend on which things you liked about both...
Zend Frameowrk is more like a library, so you can pick and choose components from it. Symfony also has some re-usable components you can use.
Really, you can do anything... it just depends how much work you want to do, and how willing you are to modify the framework code. Note: most other PHP frameworks are not nearly as flexible as Zend Framework (next up probably being Symfony).
This sounds very messy, so I'd advise against it, unless you use it in the fashion I've described above. It's easy to pull ZF or Symfony components into other frameworks, but not the other way around.
Hope this helps.
The composability of most frameworks is such that that is most likely to give you all the disadvantages of both, while simultaneously eliminating most of the individual advantages of both.
It seems to me like one framework will for serve as the core - bootstrapping, MVC stack, routing - while the other will be used to pull in specific functionality - like classes for forms or filtering or interacting with web services, etc.
As much as I prefer Zend Framework for the core - and most everything else - its use-at-will architecture argues for making the other framework the core and pulling in ZF components where you need them.
As #Adrian notes, it's easy to pull in ZF components into a project built primarily on another framework, since ZF is designed with that flexibility in mind. Other frameworks are less accommodating in this regard.
You can do it. Most modern frameworks (Zend, symfony, flow) is capable to use parts of other frameworks. Symfony 2 uses Zend Logger, flow3 uses sfYaml... It is possible tu interchange some components.
But, imho, you should stick to one framework as a core, and use second only to relatively isolated subsystems. Adapter and Facade design patterns can help you to mix them together - some components / clases demands some wrapping before use in non-native environment.
For further reading: http://www.symfony-project.org/book/1_2/17-Extending-Symfony#chapter_17_integrating_with_other_framework_s_components
Of course it is possible and I don't see something wrong with it. For example I used CakePHP and Zend on a relatively large Project which was kind of a cms. CakePHP for the core (Routing, MVC) and Zend for some "Modules". Mainly for PDF, E-Mail (smtp), FTP and a few others that CakePHP was not that good at. With Cake it was fairly easy to use ZF components and didn't feel hacky at all.
In fact, ZF was written to be as independent as possible, so that you can use any component at any time anywhere. Yet, it would not work the other way round (Using ZF as core, and Cake components). Surely it is possible, but a real pain with no benefits. So ZF could be used propably inside of pretty much any other framework and nothing would be wrong with it, imho.
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.
I use ZF a lot and I like it very much. I've learned how to solve a big part of perfomance problems with ZF, so it's became not "enormous" and "monstrous" for me.
But I'd like to know if there are any as powerful frameworks as Zend for PHP. Maybe CodeIgniter is? What is it? What are its cool features? Anything else?
And, are there any powerful frameworks which realises not MVC? Powerful means not just implementing of design pattern but a library of useful classes, functions, etc
There is a difference between frameworks, some are regualr frameworks (used to be called 'class libraries'), and some are 'full stack frameworks' (used to be called 'frameworks'). The web is and will always be about buzz-words...
Zend is a regular framework, which means you can use it's components separatly, and you aren't forced to use them. In a full stack framework, like CakePHP (I don't reallt know code igniter), you are locked inside. You can only use it's classes and they are hard to extend.
If you are looking for a competitor for ZF, be sure not to compare it with a 'full stack' framework, because it's a different thing, and it solves different problems...
Other then that, I don't know any frameworks that do not implement or give you the possibility to implement MVC, just because it's very applicable to web applications.
I'm a big ZF fan, but you can take a look to Symfony which is pretty powerfull but maybe a little to heavy sometimes.
I'd personally recommend Kohana. They just released 3.0 less than a week ago (it's in the forums, not on the dl page). It used to be a branch of CodeIgniter for PHP5, but it just underwent a big rewrite so now it's much cleaner and faster.
Basically, it does just enough to help you, but stays the hell out of your way. It's very lightweight and fast. It beats the pants off of pretty much any other framework I've used - Zend, Symfony, CakePHP, and CodeIgniter.
The thing about Zend is that you can actually decouple its components. You can use them without using the rest of the framework (just register the autoloader). Really, Zend to me is more like a heavy framework with a bunch of PEAR libraries in it. The framework is too heavy for normal use, but the components are nice.
I personally like CodeIgniter, it is good to start from 0 due to its great documentation and it can be easily expanded with the lot of plugins. It is considered pretty fast framwework (faster than ZF, Cake php and Symphony) however its speed is lowered by PHP4 support and any framework will lose its speed as you add new libraries and plugins there.
ZendFramework is the most powerfull php framework I have found. CodeIgniter is a lightweight MVC framework so its not powerful.
ZendFramework also has loose coupling so you can use some Classes without other classes like the front controller.
CodeIgniter MVC is not as powerful and the ZendFramework MVC but i haven't tried any other framework
I've choosen CodeIgniter because it is lightwight and because i'm not using a ORM and Smarty, this means i only need the router and controller/model class.
But it is missing a few features like user/login handling being the most serious.
I also use some zend classes like amazon access.