A New Approach To Dealing with PHP MVC
Posted: Thu Jan 14, 2010 11:03 pm
I've decided to take a cynical approach to dealing with PHP MVC. Sure, MVC's great, but none of em suit me. Had to build my own, but who the heck will use it but me? Can't catch some gigs that way.
Weekly it seems another guy has written a PHP MVC framework. Trying to survive in this industry, working from home, it's hard to keep up with all the smurfing technologies, platforms, and third-party APIs I need to know, let alone some company's favorite PHP MVC framework.
So I've decided to take a different approach in order to keep getting paid. Here are the only 5 things I need to know how to do with any given PHP MVC framework:
1. How to do pretty URLs with the least amount of fuss.
2. How to load a model that returns a single text string.
3. How to create a page template that uses PHP Alternative Syntax and inject it with a constant variable.
4. How to hook the bootstrap so that it loads a few of my very small goodies for common things I typically use on projects.
5. How to find the base URL.
If I can do those things, I'm home free. The client will get their controllers, their models, and their views, but I may not be using the rest of the APIs of the framework. My models (which will do the bulk of the work) will interact with the database with nothing but plain old PDO, which in my book is just good enough. No ORMs to learn or fight with, no ORM bugs to contend with, no "can't get there from here" scenarios. Just start a model, crack open a case of PDO, and start firing *gasp* SQL directly at the database like she was made to handle. And hold on to your hats. I'll also directly use $_SERVER, $_POST, $_GET, $_COOKIE, and $_SESSION, although I'll use best practices with these to prevent things like XSS attacks, etc.
Plus, let me ask you -- who's code will be more portable from framework to framework below?
- The guy who uses my cynical approach.
- The guy who uses all the APIs of the framework whenever possible.
The answer is my approach. So, if one day a framework is deemed obsolete, uncool, or whatever, or new management wants another one, then I hardly have to rewrite a thing.
Weekly it seems another guy has written a PHP MVC framework. Trying to survive in this industry, working from home, it's hard to keep up with all the smurfing technologies, platforms, and third-party APIs I need to know, let alone some company's favorite PHP MVC framework.
So I've decided to take a different approach in order to keep getting paid. Here are the only 5 things I need to know how to do with any given PHP MVC framework:
1. How to do pretty URLs with the least amount of fuss.
2. How to load a model that returns a single text string.
3. How to create a page template that uses PHP Alternative Syntax and inject it with a constant variable.
4. How to hook the bootstrap so that it loads a few of my very small goodies for common things I typically use on projects.
5. How to find the base URL.
If I can do those things, I'm home free. The client will get their controllers, their models, and their views, but I may not be using the rest of the APIs of the framework. My models (which will do the bulk of the work) will interact with the database with nothing but plain old PDO, which in my book is just good enough. No ORMs to learn or fight with, no ORM bugs to contend with, no "can't get there from here" scenarios. Just start a model, crack open a case of PDO, and start firing *gasp* SQL directly at the database like she was made to handle. And hold on to your hats. I'll also directly use $_SERVER, $_POST, $_GET, $_COOKIE, and $_SESSION, although I'll use best practices with these to prevent things like XSS attacks, etc.
Plus, let me ask you -- who's code will be more portable from framework to framework below?
- The guy who uses my cynical approach.
- The guy who uses all the APIs of the framework whenever possible.
The answer is my approach. So, if one day a framework is deemed obsolete, uncool, or whatever, or new management wants another one, then I hardly have to rewrite a thing.