Page 1 of 1
MVC.. do I really need to use it?
Posted: Fri Sep 07, 2007 11:27 pm
by seodevhead
I'm looking at jumping into the whole "framework" world of PHP to make my life a little easier and speed up my development. I am seriously considering taking the time to learn the Zend Framework, however, the one thing I think I'd rather not use is the whole MVC approach.
Don't get me wrong, MVC is probably the best thing since sliced bread, but for my purposes, it isn't suitable.
So my question is...
Do I need to use MVC if I plan to use the Zend Framework? Obviously I couldn't use their controller class and so forth, but all the other components like Zend_Auth and Zend_Feed, etc... all those don't need me to use an MVC right?
I guess this is just that one thing I really don't understand about Zend's Framework. They talk about the "Zend MVC Framework" as if you can only use it if you go MVC. Is this true? If not, is it still okay to use a framework and not use MVC?
Re: MVC.. do I really need to use it?
Posted: Fri Sep 07, 2007 11:53 pm
by John Cartwright
seodevhead wrote:I'm looking at jumping into the whole "framework" world of PHP to make my life a little easier and speed up my development. I am seriously considering taking the time to learn the Zend Framework, however, the one thing I think I'd rather not use is the whole MVC approach.
Don't get me wrong, MVC is probably the best thing since sliced bread, but for my purposes, it isn't suitable.
So my question is...
Do I need to use MVC if I plan to use the Zend Framework? Obviously I couldn't use their controller class and so forth, but all the other components like Zend_Auth and Zend_Feed, etc... all those don't need me to use an MVC right?
I guess this is just that one thing I really don't understand about Zend's Framework. They talk about the "Zend MVC Framework" as if you can only use it if you go MVC. Is this true? If not, is it still okay to use a framework and not use MVC?
You can easily use any of the components of the Zend Framework interchangably. Infact, it was designed so you may do so, and is often encouraged to make use of individual components.
So answer your question, no you do not need to use MVC practices if you simply want to use some of the Zend Framework components.
Posted: Sat Sep 08, 2007 7:29 am
by seodevhead
Hey JCart.. thanks so much for your advice. It's good to know I won't have to adopt MVC if I don't desire to.
On a related note, I use MySQL as my database and see Zend Framework offers a "MySQL Extender" that utilizes mysqli. Currently I am running MySQL 4.1.X but do not have the mysqli improved extension loaded in my installation, as all my scripts use the standard mysql extension.
I hear you run into conflicts if you load both the mysql and mysqli extensions in the same installation, so I want to stay away from that... but does anyone know if ZF offers a database extender for its Zend_DB class that utilizes just the plain ol' mysql extension (as opposed to mysqli)???? Thanks so much for any help or guidance.
Re: MVC.. do I really need to use it?
Posted: Sat Sep 08, 2007 10:58 am
by Christopher
I am suprised that there is still attitude about MVC. It as if there is some Us vs Them world where MVC and its supporters are the evil empire. Not to belabor the point, but MVC merely about two separations:
- The first, and most important, separation divides your application into two tiers or layers: the Domain layer and the Presentation layer. Quite honestly if you are not doing this already then you are not making the most important design decision there is. Unintentionaly writing Transaction Scripts is a sign of immaturity in my opinion. Dividing you application into tiers is 80% of MVC.
- The second separation divides the Presentation layer into Program Flow code and Output Generating code. Those are the Controller and View. Where the division between them is, and what the dependencies are, is up to the programmer. That's why there is so much variation and design excitement in that area. If you use templates, for example, you are making this separation. It is a the natural separation PHP programmers start making when they advance from those all-in-one PHP/HTML pages.
Given that, I believe that you are really talking about feeling uncomfortable with various Controller patterns. That is a separate issue. Just because there is a Controller in MVC, does not mean that conversely there is MVC in the Controller patterns. I believe this is a common misconception.
You're dislike seems to be specifically about the Front Controller pattern (and therefore Action Controllers). That is really an acquired taste. In general I would recommend not closing your mind off from ideas that are considered best practices. Almost every PHP framework designer has chosen to implement the Front Controller pattern. You have to ask yourself whether you are really smarter than all of them. I know I am not. I have come to see why he Front Controller is a very effective solution for PHP applications.
Finally yes, the Zend Framework is generally loosely coupled and its components can be used independently. There are some dependencies creeping in though. There is a lot of useful, well tested code in the Zend Framework that can be leveraged to your advantage.
I recall that they are doing a mysql adapter -- check the incubator or SVN archive
Posted: Sat Sep 08, 2007 5:17 pm
by seodevhead
Hey arborint,
I hope I didn't come off as starting an Us vs. Them debate.. especially since I don't know the first thing about MVC. The little bit I've researched about it I'm very impressed and think it is a great thing to do.. but just with my time constraints and current level of expertise in PHP, I think it would be best for me to move into the framework first before taking on a new challenge of learning and getting to know MVC. Especially since all my sites have fairly complex rewrite rules at the configuration file level. The one tutorial on MVC for ZF I read, required some rewriting that would cause some minor headaches with my current setup. Again, my inexperience is my biggest threat, not MVC.
I look forward to learning ZF as my first framework to work with. To this date I've probably written about 30-40 individual web applications of varying degrees of difficulty... unfortunately it has taken me this long to realize how much "premade" goodies are out there. For instance, I'm still writing my mysql commands like they teach in DAY 1 courses (you know.. $query = "SELECT..."; $result=@mysq...., etc).. Looking at Zend_DB... I can't believe what I have been missing. Little things that would have made development a little more enjoyable for me. So I'm trying to broaden my horizons a bit and take a leap into something that will help me progress as a programmer... but all I can take right now is baby steps cause of my current "bogged down" status at work.
It always amazes me how much knowledge a lot of you guys have about PHP. I'd kill to half of it. I'd imagine if I were at JCart's or arborint's skill level... I'd be enjoying coding so much more.
Posted: Sat Sep 08, 2007 5:36 pm
by Christopher
Sounds like you are in for some fun!
You may want to dabble with Zend's View first to get a feel for that part of it. Unfortunately that is the weakest part of that framework design-wise in my opinion.
One of the things that a Front Controller is allows you do a lot of the things you are doing with rewrite rules -- in code. Action Controllers allow you to distribute those rules out rather than having to have all of them always being checked. You may want to migrate module by module.
Posted: Mon Sep 10, 2007 4:09 am
by Maugrim_The_Reaper
Do I need to use MVC if I plan to use the Zend Framework? Obviously I couldn't use their controller class and so forth, but all the other components like Zend_Auth and Zend_Feed, etc... all those don't need me to use an MVC right?
The Zend Framework is a component library style framework - i.e. rather than a pre-defined way of building application, it's more like a jigsaw puzzle where you can you come to your conclusions about designing an application. The MVC element is actually a very small part of the framework - so you can quite easily drop it in its entirety, or just use parts of it (Zend_View is capable of independent usage though, yes, it's currently the weakest link - I'm part of the "improvement" team working on an updated practical set of enhancements for ZF 1.1

).
Whether to use MVC is less important, than whether you apply its basic premise - segregation of concerns. Arborint, as usual, explains it best.
It's worth noting the ZF is not the answer to all prayers. There's no real ORM implementation though Zend_Db makes a fairly clean stab for something close enough for small applications (or rather applications with not a huge amount of data/database tables), certainly it's better than the straight mysql/mysqli usage. I would recommend moving to PDO preferably, or failing that mysqli - primarily since mysqli opens up all the goodies from MySQL 4.1+, and bear in mind PHP6 will likely feature mysqln - the old mysql is out of date and is really just a backwards compatibility offering in PHP core.
Learning a framework really can be fun

. Once you get off the starting block you'll be able to focus more on the application features, and worry less about detailed coding. It's not perfect though - if you start creating something in need of specialised performance optimisation, or something which can't quite use the standard components out of the box, you'll likely need to a bit of custom outfitting (subclassing, custom library functions, etc.) to get it right. Otherwise a good framework will usually speed up development after you've had a bit of familiarity built up.
It always amazes me how much knowledge a lot of you guys have about PHP. I'd kill to half of it. I'd imagine if I were at JCart's or arborint's skill level... I'd be enjoying coding so much more.
Most of the Gurus have had years of headaches before being capable of answering such questions

. Give yourself some time and you can become a Guru too!
Posted: Mon Sep 10, 2007 6:55 am
by Chris Corbyn

Moved to Theory & Design
