I get asked a lot if MVC Frameworks are useful or not and when they should be used. I think the answer to that questions can be answered generically. Let’s face it, it’s project dependent but there are signs when and when not to use them.
First of all if your going to need some of the basic web related stuff like session management, database connections, profiles, editors, etc then yes use a MVC Framework. They have built in systems to handle everything you will need to start so you can jump right into coding your custom system. Secondly most MVC Frameworks have built in profiler, helpers, OS and driver classes and functions. I can’t tell you how many times I am knee deep in coding and think “I need to benchmark this function, let me write a system to do that”. I end up spending some time playing around and creating a benchmarking class or function taking away time from what I was planning on coding. Using a MVC Framework let’s you leverage pre-made classes and functions for when you run into a situation where you need something quick and you don’t want to spend the time making it yourself.
Here is a quick list of things I find most useful from using CodeIgniter (my MVC of choice).
- Multiple Database Drivers
- Session Management
- Benchmarking
- Code Profiling
- Built in Security
- Rapid Development
Within an hour of starting a project from scratch you should be able to have all your basics done. That’s what a MVC Framework is for.
Now why would you not use a MVC Framework if they are so great? Simple, the learning curve is destroyed when you just start calling functions and creating objects. Even looking at the source of each function and class call your limiting your idea of how it should work based on what the developers of the MVC Framework do. I have been programming PHP for 14 years and I can tell you there are hundreds of ways to do the same thing. I am from the self-taught group and I hate to use code I did not write or modify and that led me to many years of re-creating the session handlers and the database drivers, the URI parsing and all the elements of a CMS. I have written 4 CMS systems from scratch over the years and it has taken a lot of time to learn each part of the system and secure it, make it fast and optimized, make it OS independent and extensible.
I think at that point your not just learning how to code PHP your learning how the internet works and how technology on the internet is used and exploited. It’s not just about learning how to make a login system, today coding and developing something is learning how people will use it and how they expect it to work. The bar has been set high and you can’t just create a website with a MVC Framework and it be great and innovative. It’s more about the idea now and not the system.
To sum it up you should use a MVC Framework when you are in need of a rapid deployment situation and you have a grasp on the systems you will be “auto-generating”. You should not use a MVC Framework just to use it or if your doing it just because you always have. Be adventurous and try and create one yourself or go old school and write your own system.
You want to be innovative right? Not just doing the same thing over and over, you know Insanity.