ive seen many third party mvcs or frameworks such as codeignitor , cakephp, and so on. what i want to know is what are their purposes? ive created my own framework call it an mvc or framework (in my opinion their all the same). in my framework i have all the classes in one folder called classes and all functions in another. its all organized and when a new project comes in i am able to complete it fast. i have looked at the applications that i mentioned and it seems to have huge articles and tutorials to study. what is the purpose? why not study the main language such as php, javascript/ajax or jquery, and so on then build something that you know the ins and outs of so that any project comes your way you know what to do. ive known some people who use cakephp and for every project they get stuck and need to figure out what to do. another guy i knew worked with joomla and every basic company website that came his way he would reverse engineer joomla to make it work with the site. are people using these applications because they lack knowledge in the languages? or sometimes have no choice but to make a site while lacking language and put something together.
ps: i dont want to say which is better or argue, i want to understand and see if im missing anything.
Standardized frameworks make it easy to adapt and reuse blocks of code. By using a framework such as Zend, Cake, Joomla, etc. you can find repositories of pre-made scripts and components that easily plug into your existing site.
Not only that but frameworks will (in most cases) handle a lot of complicated, repetitive tasks that are standard across most websites. Frameworks will in most cases scaffold CRUD classes against your database automatically and support a clean separation of logic and view.
Frameworks aren't for everyone and I would actually recommend that newcomers to programming or PHP learn the basic syntax and object structure. Doing so will give you a stronger understanding of how your framework behaves and make it easier for you to modify/override the existing structure. Every framework is different, and some are better suited than others for particular tasks. You should do research and testing to see which one fits your needs.
One other benefit that hasn't been mentioned yet is that using a standard framework gives some shared knowledge between developers. If you build a project with your home-grown "framework" and then someone else has to maintain it in the future, they have to totally learn your methods from scratch. However, if you had used CakePHP, and they already have experience with CakePHP, they're going to have a pretty good base to start with. That can make a huge difference in the amount of time it takes them to get comfortable with a new system.
If you want to setup a project quickly, without having to know too much about everything underneath, using one of these frameworks can be very useful. You know, to some extent at least, that they're pretty well built and reliable, and it saves you a lot of time opposed to creating everything yourself. Most of them are also easily extendable to add functionality you might need.
But you're right, it's always a good thing to learn about all the basics. That way it's a lot easier to know what these frameworks exactly do, and more importantly, why and how. And knowing that makes it easier to choose the right framework for you and extend it in a proper and efficient way.
But in the end you'll learn from both approaches, the difference being that with an existing framework you can get start working with a site (almost) right away.
I too use my own home-built framework that took many months to develop, but for every project I still weigh the pros and cons of using a 3rd party framework. The decision usually comes down to the specifics of what I want to achieve. For example, in database-centric applications, I use my own framework because the ORM solutions of most of the well-known frameworks are just downright terrible and inefficient, but for something simple like a Blog, Codeigniter might be my choice (just because I hate Wordpress, which isn't even a framework but I have to mention here how horrible it is).
But keep in mind that while you know the ins and outs of your own framework, if anyone else has to maintain your project later on it will be difficult especially if you don't document. Big frameworks like CakePHP, Kohana, Symfony, etc. are fairly well known and it's easy to find others who have experience with them. Plus if you need help, all you have to do is post on their forums and chances are you'll have a good answer.
Another point is the maintenance of a home-built framework. More often than not this comes second to developing new sites or maintaining old ones, whereas a standard framework has a team of developers behind it. Any security issues in the framework are addressed and patched more rapidly and you can usually just upgrade the framework and keep your code intact.
Related
I'm looking for some kind of CMS or framework + ORM (I don't really know exactly what I'm looking for).
My goal is to build a web app to view and manage database records.
To help understand, I would like some sort of end-user phpmyadmin/CMS hybrid with minimal programming efforts. In fact, that is to build a database of a particular kind of products, where those are submitted and consulted by end user and validated by myself.
I first thought that wordpress + plugins, mediawiki + semantic or drupal could be quick solutions but
those are quite heavy for the purpose.
Playing with tons of plugins don't reassure me, as they can become unmaintained, conflicting, ..
Solutions like mediawiki requires bunch of time to write templates, etc..
Then I thought at using a framework (let's say symfony) but it's also very time-consuming (compared to an almost out-of-the-box solution).
Finaly, I thought that the quickest solution may be to develop it all by myself using an easy ORM (like RedBean), but I wish I could find a quicker solution.
Any idea ?
Note: I intend to use a php/mysql solution.
There are plenty of "micro-frameworks" for PHP that work very well with RedBean (which I love btw). It's a compromise between writing everything from scratch and using a full blown framework. I find their is a good degree of flexability using these small(ish) tool kits.
One I've used a little bit is Slim, which gives you routing and some other small things a controller would.
Other similar "micro-frameworks" like Slim:
Silex
Limonade
GluePHP (which is about 30 lines of code)
These all give you routing and some other neat tools. In regards to MVC, they sorta give you the C.
If RedBean is your Model, or the M, all your missing is the V, should you want the whole MVC organization.
For that you can use Smarty, Twig or Mustache, or any other templating tool.
I personally love working with these components separately, because I find that they are all highly specialized, integrate nicely, and allow me to control to what extent they are in charge of things. The downside is is that they may have compatibility issues with each other and that you have to maintain three, as oppose to one, third-party library to update and depend on their development.
Here's a good article on using Slim with Idiorm (an ORM) and Twig, though I find Idiorm rather nasty to work with.
Sounds like you could use:
asp.net + mvc or django
Sorry these are two different comparable environments that should help with not a lot of overhead on learning, and can function quite well with mysql
I am building an application currently in PHP and I am trying to decide on whether to use a pre-existing framework like codeigniter or build my own framework. The application needs to be really scalable and I want to be completely in control of it which makes me think I should build my own but at the same time I dont want to reinvent the wheel if I dont have to.
Any advice greatly appreciated.
Thanks
Use an existing framework.
First of all creating a framework from scratch represents a massive investment in time and effort. The process involves a lot of trial and error, because you're designing something that needs to be both simple and powerful. For every design decision you'll have to ask yourself how it will affect every single future project that will be built on your framework.
You'd think that you could take each design decision and weigh it against the requirements like you would do for any other software project, but the thing is you don't know your requirements. You can't know them, because a framework is supposed to be able to do almost anything (or have the ability to be extended to do almost anything) within its domain. Future project a will need to be able to do x. Can your framework allow that without turning it into spaghetti code? And what if project b needs to do y? What if project c needs to do z?
Have you predicted everything?
Now the normal response to this is that if something doesn't work, you'll just change it in the future. It's software after all. A framework however isn't like a simple application. It's supposed to have an interface and once you expose that to the software that will be using it, you can't change it. You can extend it, but not change it. So now you have to think about deprecating methods, api versions and version compatibility. It's a whole new set of problems to deal with along with normal framework maintenance and new application writing.
Then there's documentation. You need an API, tutorials, example code. Once you build your own framework you have to deal with this as well. You could ignore it, but I assure you that eventually you yourself will need to find out what that method you wrote 6 months ago does. What does it return? What if special case x happens? Have you written all that down, or do you need to step through the code again? And I wont even mention how easy it will be for a new team member to get started on a custom framework whose documentation lies completely or at least mostly in your head.
You also have to acknowledge that unless you're working with the very best and brightest (and have a budget to match) you'll never have the extensive set of libraries that existing frameworks boast. Can you analyze, design, code, test and debug faster than an open-source community?
Finally you should ask yourself if you are proficient enough to be writing a framework. Have you dived deep into the code of a modern OO PHP5 framework to find out what makes it tick? And most importantly do you know why it does things that particular way? Keep in mind that any mistake you make in your design can blow up in your face months from now and you can end up paying for them over and over again.
To sum things up I'd advice you to go with an existing framework; it doesn't mean however that you have to pick one and like it. Take the time you'd otherwise devote to developing a new framework and devote it to learning an existing one. Then you can extend it to fit your needs. Also remember that there could be things you wont be able to do. But I assure you there would be things you wouldn't be able to do with your own framework either, so it doesn't matter all that much. A framework imposes a few limitations. It's the price you pay for being able to develop applications faster.
Make a list of requirements for your framework (ORM, PHP 5.3, PDO, etc). Then iterate over the existing frameworks and narrow them down to find the ones matching with your requirements. Then look at the codebase, documentation, community, project activity – does it feel something you would like to work with? Also be realistic about the time needed to to implement all your requirements by yourself – do you want to focus to building an application or a framework?
I'm building my own and I'm very glad I did in terms of learning, which is important to me. Also I LOVE to be in total control of my code. It comes with lots of negatives though, the big one being I'm the only one that knows how to use it. Also, a lot of development time is spent on improving my framework rather than delivering products to my clients. But I can't stress enough that I really, really enjoy building and using it.
If you want to learn (A LOT) build your own. If you just want to get work done use an existing one. (Before starting my own I almost went with CodeIgniter)
While I've build my own CMS framework in the past, and used custom (in-house) general php frameworks, I'd find an active framework that fits your development style, and use it.
Unless your main product/application is the framework. But it doesn't seem that way.
Your concerns about control and scalability should be applied to the host of frameworks out there - giving you a short list of options that fit your requirements.
Certainly, it's not a question of 'in-house' vrs 'public', then once you've made that call just pick any old framework.
To answer the question behind the question, for a framework that gives you complete control and should be able to scale reasonable well (I'm not sure how you need the framework to scale), I would suggest the Zend Framework. You can use single parts of it, rewrite what you want, and it's far more than just a MVC implementation.
Update: A quick example of customization with Zend. If you don't want to use their MVC stack, but need something to route requests, you can just use Zend's router library. If you like the MVC stack, but hate the way the router works, you can just implement the interface and write your own router.
This applies outside the MVC stack as well. Zend has a ton of libraries for mail, rss feeds, caching, auth, db, etc. Use what you want, and ignore the rest. Extend what you want, most of the framework is tiered with interfaces/abstract/generalized classes that you can build on if the standard functionality doesn't suite your needs.
The decision is very plain and simple.
If you want to learn and have full control - go for your own
If you want just to make money fast - go for ready made one.
I work in a company that initially wrote its own framework, built by a guy that worked here. It was only used on one project. The reason for this is that we soon realized that although it was clever and very good, there was no documentation for it. So if we employ another developer or a freelance guy, they'd have to learn it.
We run with CakePHP for a while, which is popular, but it does seem a mess. We eventually settled on KohanaPHP. Easy to extend, some good documentation (probably not up there with some others though), nicely formatted code (meaning if you can't find documentation you can quickly work out whats going on). The way the framework is written makes it pretty easy for a developer to pick up and follow what is going on. Whereas we always had trouble doing this with CakePHP.
I think the only argument for rolling your own framework is that you may want some highly customised stuff. But Kohana is so easy to extend, you can just throw it in there. You don't have to use their packed libraries if you really don't want to.
That said, some project I don't bother with a framework at all, just some sort of routing solution, like GluePHP. Since it would be overkill to use a full stack framework.
If you were just trying to practice, I'd suggest writing your own. Otherwise, though, definitely go with using an existing one. Symfony ftw.
The short answer is symfony2 IHMO.
The reasons are:
do not reinvent the wheel
a good wheel is better than yours (others are professional wheel makers,
since a lot of time)
an OSS framework can be expanded or modified, even only inspected
first or later you will not have time to maintain your own wheel
a number of eyes and hands do it better than 2!
Of course the previous points are valid for a very small set of professionally made frameworks! My favorite is symfony2, but there are a number of good alternatives.
So, I'm very tempted to rewrite my application using a php framework, as I think it'll make it easier for folks to get involved, as well as improving the design of the app.
CakePHP looks like the best of the PHP web frameworks. Does anyone have any experiences of it? What are the caveats I should consider going from handcoded PHP to using a framework?
Not depending on the framework you'll chose, the first thing you have to know is that :
it'll take some time for you to know it
you'll do crapping things, during that time ^^
so, take into account the fact it'll take some time before you are fully operational :-)
I think those points are the most under-estimated points : using a framework takes not much time... Using it well and to the full extend of its abilities takes... Well, a couple of months, maybe... Which means, when you are at the end of your project you'll say "I should rewrite that with all the stuff I learned while re-writing it the first time" :-D
What it means is : learn what the framework can do, learn how to use it, and use it for a while on small applications, before starting rewriting your big one !
Then, there is probably no "best framework" : one framework may be very well suited for one project, and another one may be best for a second, different project.
I've never worked with CakePHP ; I really like Zend Framework. But that is a personal opinion, and O know people who really like symfony ; they are not wrong : symfony is great -- and I am not wrong either ^^
Still, we sometimes agree on some things ; like the fact that Doctrine (default ORM layer of symfony) is really great stuff, and we tend to use in both symfony and ZF-based projects...
If motivated, you can take a look at many posts on SO, about frameworks... Here are a couple of those :
What PHP framework would you choose for a new application and why?
Is Symfony a good framework to learn?
What, in your mind, is the best PHP MVC framework?
Is Symfony a better choice than Zend for a web development shop (10+) because it is a full stack framework?
Best PHP framework for an experienced PHP developer?
Good luck with those ^^
("Which framework" is a quite pationnating -- and subjective -- question ^^ )
CakePHP has it's good parts but there is no "best" framework. Here's a thread with some clues about what's good in most popular PHP frameworks.
If you never used MVC frameworks before (and Cake is MVC framework) I think you should first familiaze yourself with MVC architecture.
"CakePHP looks like the best of the PHP
web frameworks."
This is subjective. You should compare the pros/cons of other PHP frameworks that will suit your needs.
These posts may help you:
https://stackoverflow.com/questions/2648/what-php-framework-would-you-choose-for-a-new-application-and-why
Why do I need to use a popular framework?
https://stackoverflow.com/questions/249984/php-framework-decision-analysis-paralysis
FWIW, I used it for a time when I was doing some php development. I found it easy to use, and the rapid development aspect was great, and I would imagine has just gotten better in the last 3 years. There is a ton of help in the irc channel, and the documentation is good. I didn't stick around in PHP long enough to become an expert. However, I was just starting out as a programmer then, and ran into Larry Masters (the creator, aka phpnut) and he was just a good person to talk to about design principles, and an all around nice guy. Then again you don't have to be a super nice guy to write a good web framework (I'm looking at you DHH).
Most of the frameworks "bind" you to them, meaning you have to do things their way. If you want to do something they weren't designed to do, you usually have to hack it. For example, how many PHP frameworks currently support Facebook Connect?
Personally I prefer "frameworks" that you can use only the parts you want. Zend is like this, Doctrine and Propel are ORM that are designed to be used with other code. For example, the Symfony framework can use either.
Finally, I haven't found a popular PHP framework that scales well.
I have used cakephp for a couple of projects. From the moment I learned it I have never written php again without it (unless is fun code in which I want to try some new stuff, or learn other design ideas away from MVC). As mentioned, learning it will take some time. How much time it takes really depends on your background. If you have used another MVC framework for a web scripting language then you will learn it really quick; RoR developers will pick it up within hours/days. If you don't have experience with MVC frameworks then it might take you a little bit, but it will really save you time later on the road (including in that project you start with).
Until today, I still learn new things about CakePHP every time I start a new project on it, although I do dig into a lot of its source code (you definitely don't need to do this, documentation and help boards are more than enough).
I definitely recommend you looking into it. It will save you a lot of time and get your head thinking in a different way (if you are not used to the MVC).
Best of luck.
CakePHP's convention over configuration approach has a few advantages once you learn them:
it helps to keep you code organised and understandable
makes it easier for multiple developers to collaborate on the same application
makes it possible for developers to understand other developers' applications
You have two main options when rewriting a legacy application in CakePHP:
change the database schema to reflect the conventions - resulting in less code
code your models to interface with the legacy database - this book goes into all the details
Either way, once you have done the above, it's pretty much plain sailing, and a good learning experience.
This isn't a question about what framework to use. I've learned both Rails and Django, and I write all of my webapps in PHP. My question is why bother with the frameworks? It's always taken me longer to use a framework than to reuse old MySQL code and build "models" with phpMyAdmin. I also like writing everything myself, because I know what's going on. I can still reuse functions, etc. and do things how I want, and this freedom seems to be missing from most frameworks.
I'm not saying that my way is right; in fact, I'm trying to figure out where my logic fails. The hype can't be just thin air. What am I missing?
The basic idea of a framework is to allow you to work at a higher level of abstruction and write only the code you have to write to implement your specific requirements. All the other repetitive stuff is handled for you by the framework, and probably with far fewer bugs and security holes than if you did it yourself.
It may feel like it takes longer to learn a framework than to just do it yourself using basic language features and standard APIs, but it's simply not true - not if the framework is good and the app is non-trivial, and especially not once you have learned the framework (using a different one for each new project would of course be idiotic) and factor in the time it would take to find and eliminate all the bugs and correct all the design mistakes that have long since been found, eliminated and corrected in the framework by its developer community.
Almost every developer has cowboy coder instincts that tell him "Doing things yourself is much more fun than using code others have written, and I'm sure I'm good enough to get it right the first time, so it will even be faster and better!". These instincts are almost always wrong.
Frameworks allow you to concentrate on the application itself rather than worrying about the boilerplate code that you'd otherwise have to write for every application. They allow you to structure you site in a much more logical (mostly object-oriented) way, using tried and tested design patters such as model-view-controller. The code in framework is generally more mature and of a higher standard than code you would write yourself for one-off projects as framework have a large community of developers perfecting the code perfecting the code over year. This means that framework-driven sites often perform better and are much more secure.
You also mentioned you like writing things yourself - I know where you're coming from. My solution to this was to write my own framework - I get to reuse and improve my code with every project I do and I know the entire codebase inside out.
Writing it your self may make it easier for you to understand things your self but unfortunately it can make it much harder for other developers to understand what is happening. Frameworks will often be better documented and have a larger community that can support a new developer that is working on the app that you wrote.
I think a big part of it is what you focus on. Frameworks standardize the parts that you shouldn't have to keep revisiting, which helps you focus on the application as a whole. If you reuse your own code all the time you're already using your own makeshift framework.
Your comparing a framework (Rails) to a language (PHP). A framework is going to give you pre-built components so you can spend time on what makes your project unique.
You may already have a code base that helps do this for you. Check out some of the PHP frameworks since that's where you are more comfortable. Take a look at CakePHP, CodeIgnitor and/or Zend Framework.
If you are building many small apps/sites, using a framework may make your life easier.
I think a good step for you is to create your own framework with the code you've programmed so far. ;)
Try to make your code parametrizeable, in other words: create components which you can reuse in different parts of a website (for instance: styled containers), or in different websites (form generators/validators).
You can even go further and create base-classes from which you extend new classes to build your websites. (for instance: data objects with generic select/insert/update/delete methods).
I bet this gives you the best view on why frameworks are so damn handy ;)
It'll take you longer to initially use a framework for the same reasons a PHP developer would take longer to initially use Ruby - you're not familiar with it.
Once you're familiar with them, frameworks can offer the ability to skip the mundane and focus on actually writing the important parts of the app.
You should also just use a PHP based framework like Symfony or CakePHP using them should reduce your production time considerably.
One reason to use a frame work is code separation. Take symfony for example. The model is all done with propel or doctrine libraries. Very little SQL needed. You instantiate a new object and user getters and setters, to store your data, and instead of writing SQL in your page code you create functions in the objects related to the query. When you need to access the same kind of data on different pages you are asking the model for it, keeping the business logic with the model where it should be, so there's never any difference. All the work is done in the "action controller function". You get all the data you need, and then put as little php in the display, basically just echoing the variables you got in the action controller, (with the exception of some for loops and if statements for conditionals. I have found this a more efficient way to code, and on my 2nd project saw the production time cut in half.
You don't need to learn a new language python/ruby just to use a great framework, just have to fin one that works for you.
First, PHP has frameworks too, so the question as stated misses the point.
Yes, you can write your own framework, and as Kris said, there's no shame in that. However, part of the leverage of code reuse is the collective value of the efforts of many. It's not just about reusing your own code. Frameworks encapsulate the common tasks and patterns we all share and provide well tested solutions with many iterations of improvements from the community. No individual effort is going to measure up to that, no matter who you are.
If you roll your own, it will only become world class due to the collective effort of world class people, and that will only happen if your idea merits the attention. The top frameworks out there are already proven on those criteria.
DHH is a smart guy, but the Rails we have today never could have been realized by him alone. Not even close.
If you like "writing everything yourself" as you say, then choose a framework with a core philosophy that matches yours, and start making core contributions in the areas where you can see room for improvement.
Depending on the functions of your Web Application, it can be faster to develop without a framework. For example when the Webapp is just some kind of data viewer.
But as soon as you begin to implement more advanced functions, you are much more efficient with a framework.
Try do do this from scratch:
- proper Form validation
- Handling of multiple Language and Date/Time formatting
- Authentication
See a framework as free tools and stable implemented function for you to use.
Sounds to me like you have already written your own framework in php, since you do mention code reuse.
I can imagine it being easier to use your own set of wheels instead of adapting to someone else's. No shame in that.
Frameworks are there mainly to help people who are semi-new to PHP (or the specific language it is built on) to be able to build a website to an extent that it is secure and easy enough to add on extra parts to the site without having to know a lot about the specifics like security, MySQL (or other database types). In my opinion it is a fairly good way to help break coders into a language, allowing for the fact that the framework isn't too complex of course.
EDIT The reason behind me saying they are for beginners is because myself, as a beginner has used frameworks to break myself into languages a lot better.
I have a relatively simple application up and working with some basic functionality which i have built as a bit of a project. I would like to now build on that, and add some more complex features, including login.
The code has got quite complex, and it's written in plain php, so all the presentation code is mixed in with the logic. I have decided that before I go any further I'd like to re factor it to separate this out, so it's easier to maintain and add to. I've been researching MVC and think that's the way i should be going.
I had decided to give the zend framework a go, and have spent a while trying to get to grips with it, however I have found the learning curve extremely steep as I have no object oriented experience.
Is there another framework or option that anyone could recommend? I am considering having a look at cake based on reading other posts in this forum but I'd accept any guidance - my "requirments" are
easiest to learn for non OO experience
includes some login / authentication features
handles database interaction with mysql easily.
All suggestions appreciated!
As stated very eloquently here already, frameworks are good until you want to do something they're not suited for, plus they can abstract the language to the point where you're effectively learning them rather than the language you're coding in.
I would encourage you to roll your own. If you understand the principles of MVC and you have a fair-to-middling knowledge of PHP then it won't be too hard (there's already several pointers around), plus you'll come out of it far further ahead than if you'd just used someone else's.
Smarty templating engine.
http://www.smarty.net/
I've personally used Symfony. It's a very complete and well-supported framework which is relatively easy to get started with. My experience with frameworks is that for simpler projects they can be quite a burdon.
The people at my workplace swear by Cake. It does seems to be quite flexible and certainly fast to develop with once you know it. However, I would echo da5id and say that it's always safest to build your own - you know exactly how it works, you get some good PHP experience (instead of Cake experience), and you don't have to spend hours either fighting with it to get it do do what you want, or reading up on how to use it in the first place.
I am not at all convinced that "MVC" really exists as a paradigm in PHP incidentally - the V and the C are so hopelessly intertwined in most cases because the form is the view.
Build yourself a code generator that will output PHP classes based on your database tables. If you're really clever you can get it to inspect the database for relationships and even build the joins in PHP too. Then create a second set of classes that each inherit from the table-based-class that lets you customize its behaviour. Rely on these secondary classes in your business code. (It's a form of the Generation Gap pattern)
In addition to being a framework, Fat-Free also has its own templating engine that goes beyond just variable substitution. It allows you to invoke functions and class/object methods along with familiar PHP-like expressions.