views:

1942

answers:

8

There are lots and lots of opinions available about what framework is the best choice as well as resources and tutorials to help you learn to use them. What I'm having a hard time finding is a clear explanation of what the "ah-ha this is why I learned all this" moment.

So just to clarify, I have never used any framework and don't really understand how MVC works beyond an extremely basic level from an ill-fated attempt to learn rails a couple years ago. I think I'd like to learn, but before I dive in, I want a little clearer understanding of what problems it will solve. The common answer is something along the lines of "it takes care of all the bs stuff and lets you focus on what's important." That sounds great, really, but I don't know wtf it means in practice.

To give a little more context...I am very much a novice and at this point am only focused on PHP. I am currently working on an app that (in a very basic sense) aggregates and displays parsed data from various web services...has a login system with individual user settings that determine how each user sees/uses the data. I realize that description is pretty vague, but hopefully it's enough to explain to me the virtues of programming like a grown up.

Happy to answer any other questions about my specific situation if that would help with the explanation.

Thanks

+2  A: 

An important approach when programming is "How do we structure our code to make it readable and easy to use?". This is where the MVC and Frameworks comes in handy.

A framework is a set of tools to make your life go a little bit easier so you never have to re-invent the wheel.

And MVC helps you seperate different layers in your programming such as

  • Logic
  • Data
  • Design

Look here for what Phil wrote on MVC and MVP

So these "steps" and ways of work is mainly to help you, the developer. Make your life easy and re-use code, use good stuff which is well tested!

Filip Ekberg
+5  A: 

Separation of Model, View, and Controller:

  • Allows re-use of business-logic across applications
  • Allows development of multiple user interface's without changing business logic codebase
  • Discourages cut-&-paste repetition of code, streamlining upgrade and maintenance tasks
  • Enhancing ease of testability

REF

cgreeno
+1  A: 

One of the reasons I found for using the MVC paradigm is that I can have the designers work on the template or view, the database guys can focus on the data and then the developers can create the business logic. Frameworks such as Symfony and CakePHP are great for stuff like this (PHP specific, as per your uses). One nice touch is that you can typically generate the data objects with a simple command line call based upon what's already in the database.

Kevin Eaton
+4  A: 

You don't have to. I have worked with PHP for years and have never used a framework with it. This is because everything that I have done with PHP has been very straightforward and using a framework would have been overkill. The more functionality that you have the better off you'll be using a framework.

The benefits of a framework are that you inherit a lot of functionality already written for you and it provides a structured way to extend that functionality. The cost of using a framework is that it may be more complicated to do some of the things that you are used to doing. You have to weigh that against the benefits you get from using it.

I find that each of the PHP MVC frameworks usually have a page about their benefits. CakePHP has nice brief one.

I would recommend that you check out a few of the MVC frameworks for PHP and look at what they provide. If they sound like something you could use then pick one and learn it.

You might be interested in something like this "The no-framework PHP MVC framework".

You shouldn't feel pressure to use MVC or a framework. Only use it if you find that it works for you. You'll go much further in this business if you do some research, experiment, and then use the things that work for you.

bruceatk
I've looked at CakePHP and Symfony (and briefly at some others) and they all seem to be too heavyweight to me, in that you need to modify/create too many files just to do simple things (imho).
cletus
@cletus. I agree. For most of what I do they are overkill, but if I was going to create a full featured site in PHP I would use one. I don't know which one, but I would definitely pick one.
bruceatk
+2  A: 

One of the reasons that I have found using a framework helpful is because as a language PHP is pretty ugly. Its also VERY possible to do some very ugly things with PHP that make regular programmers cringe. See this question for more criticisms or defenses of PHP. Frameworks attempt to help resolve this issue by providing a more structured API to work within.

One of the ways that frameworks can help inexperienced programmers write better code (assuming that they choose a well-written one) is that it provides a coherent well-structured API that can be used to help you decide how to structure your own code. Just reading the source code for the various frameworks can be a real education on things to do/not do.

Another way that using a framework can be very helpful is that it will present to you industry accepted and tried design patterns for abstracting concerns and encapsulating your application within layers. While forcing you to learn what MVC is and how it is to be used, the framework will also present you with an already-built robust API to begin using the design pattern in your application. Additionally, most framework provide some sort of Data Access Layer API.

And then there is always the fact that most framework API's provide wrappers for some of the ulgier PHP functions and code that we've generally had to interact with directly.

With all of that said, I personally prefer Zend Framework as I've found that its developers have stuck to the 'configuration over convention' mantra in designing its API and thus I'm allowed to take parts or leave parts as I find it necessary. Additionally, I have found that its some of the consistently best written PHP code that I've ever seen.

Noah Goodrich
+2  A: 

I've been programming with PHP/MySQL for years, and I've never used a single framework. My style, and organization has changed dramatically over the years. I noticed that I would slowly move PHP out of HTML, and wait until the last minute to print/echo any output. I started splitting my pages up into config files, etc.

Finally this year I started looking into different MVC Frameworks in PHP and to my surprise much of what I have naturally been moving towards is the same exact thing in these frameworks. The frameworks are even more organized, and better-constructed, but they are essentially what I started doing naturally as I became smarter, faster, and more efficient.

It is for this reason that I've decided to find myself a good framework, and stick with it. Because if this is where I would eventually end-up naturally, then I'd be a moron to put it off until later.

Not to mention the helper classes are very attractive to.

Ask yourself this, why would any Javascript developer use jQuery? I think then you'll have your answer to some degree.

Jonathan Sampson
+1  A: 
Perpetualcoder
+1  A: 

MVC allows you to develop your web application in a disciplined manner, you will follow a set of directions that basically specifies the following:

  • View: Markup (HTML,XML, etc) with very little logic, typically nothing more complicated than a loop or conditional.
  • Model: Business logic and data store interface.
  • Controller: Connect Views and Models based on request.

By following a discipline, debugging and future support of your application should be a much more straight forward process. Below I've listed some Zend Framework components which I think would directly help you in your development process:

jakemcgraw