A New Approach To Dealing with PHP MVC

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
jack_indigo
Forum Contributor
Posts: 186
Joined: Sun Jun 08, 2008 11:25 pm

A New Approach To Dealing with PHP MVC

Post by jack_indigo »

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.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: A New Approach To Dealing with PHP MVC

Post by JNettles »

I agree with you about the ubiquity of "technologies". I browse Zend Jobs or Monster or CareerBuilder or any other jobs site and with every developer job I see a plethora of technologies just spewed out onto the page, often in a way that leads me to believe the person posting them actually has no idea what they are for, only reciting a list of "hip" techs that big firms like to use. I've lost track of the number of startup projects I've seen where the managers have already decided to use Zend, Cake, Joomla, etc. with absolutely no input from the development staff they're looking to hire.

Also, debugging these massive frameworks is a nightmare. I'm working on Joomla components right now and if I did a line-by-line debug (doing nothing but holding down F5) it would take an hour for the whole application to run.

And for the love of light, I don't use an ORM unless its a data tracking system where I'm going to be doing CRUDs every other second.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: A New Approach To Dealing with PHP MVC

Post by jayshields »

I don't know what the point is that you're trying to make -- you hate everyone else's frameworks?

It seems the only thing I have to say on this matter is that if you can't find a framework then just roll your own - and do whatever the hell you like with it!

I've been using CodeIgniter exclusively for a few months now and I probably won't ever use anything else. I wrote my own small framework before I got into CI, which I think is a good thing to do before choosing a framework because it gives you a better opinion of what suits you.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: A New Approach To Dealing with PHP MVC

Post by Christopher »

I think your approach of building Fat Models and learning the minimum to get Controllers and Views to work makes some sense. If you use a more RESTful approach then you should not need Controller bells and whistles. If you push a lot of the View work into a standard Javascript library that you use, that simplifies Views and templates. I think the approach has some merit.
(#10850)
jack_indigo
Forum Contributor
Posts: 186
Joined: Sun Jun 08, 2008 11:25 pm

Re: A New Approach To Dealing with PHP MVC

Post by jack_indigo »

Yeah, this isn't really an attack on fans of a particular framework. You love CI, go use it. ZF you're thing, more power to you. The point is someone who has to float around from gig to gig, who often times doesn't get a chance to choose the framework. That's me. I can't keep up. So, I threw up my hands and said, "You know what? There's a better way to manage this which sort of keeps the most people happy and gives me some sanity." And that's when I came up with this cynical approach.

The second point I'm trying to make is that I'm picky and can't choose a favorite framework. Given the choice, I roll my own MVC. But I don't often get that choice and have to live with what's been chosen already.

The third point is the fact that someone who takes this cynical approach will actually have the more portable code from framework to framework. And sometimes that's important.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: A New Approach To Dealing with PHP MVC

Post by alex.barylski »

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.
Double edge sword, IMO. On one hand, having a single standardized MVC framework, like Microsoft, means there is less to learn as a developer. On the other hand, I think building a framework is an excellent learning experience.

Although MVC is interpreted so wildly different by so many developers, it does result in flame wars, confusion, etc...but if you have ever worked on a large system 100K+ lines of code that is cobbled togather as a series of transaction scripts, than any interpretation of MVC is better, so in that sense I have no complaints.

Although I do not buy the argument that Zend does not meet anyone`s requirements. Its designed in such a way so as to facilitate anything you could probably imagine, you just have to invest the time into learning it -- which is still less time than building a framework yourself. Yes, somethings are overly complex and feel un-intuitive but still.

Cheers,
Alex
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: A New Approach To Dealing with PHP MVC

Post by Benjamin »

jack_indigo wrote: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.
I don't disagree with your programming approach at all. However, I would argue that it is not the job a programmer to understand the intricacies of all frameworks. The job of a programmer is to understand how to translate task requirements into computer logic. The quality of the resulting computer logic can then be judged based on numerous factors such as how well it performs, whether it has bugs, how scalable it is and how adjustable it is (adding / removing / modifying features etc).

So the point here is that the true skills to focus on are not learning everything about every framework. I would choose a programmer who had no experience with a particular framework over a programmer who had years of experience with the same framework if I felt that he had a better grasp of how code should be written.
Post Reply