Home arrow Blog arrow MVC, for You, for Me,for PHP
Shameless Plugs
Main Menu
Home
Blog
Contact Me
Development RSS Feeds
IT Healthcare RSS Feeds
Prephotosts
Hire Me!
AdSense
The RPNA, 1 kB
MVC, for You, for Me,for PHP PDF Print E-mail
Written by Edward Prevost   
Friday, 16 February 2007

Does one need to know other Dps before MVC?

It's a good question, and one that all OOD focused PHP'ers need to address at some point in their careers, as MVC is probably one of the most popular design patterns, if not the one with the most frameworks readily available for PHP. It is also probably the simplest, in that it directly groups the process-flow of an application into it's major components. (Singleton would be the simplest from a scripting perspective)

As defined by WiKipedia-
Model

Quote:

The domain-specific representation of the information on which the application operates. The model is another name for the domain layer. Domain logic adds meaning to raw data (e.g., calculating if today is the user's birthday, or the totals, taxes and shipping charges for shopping cart items).

Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the Model.


View

Quote:

Renders the model into a form suitable for interaction, typically a user interface element. MVC is often seen in web applications, where the view is the HTML page and the code which gathers dynamic data for the page.


Controller

Quote:

Processes and responds to events, typically user actions, and may invoke changes on the model. Mach-ii for example, which applies implicit invocation beautifully.

Though MVC comes in different flavors, control flow generally works as follows:

1. The user interacts with the user interface in some way (e.g., user presses a button)
2. A controller handles the input event from the user interface, often via a registered handler or callback.
3. The controller accesses the model, possibly updating it in a way appropriate to the user's action (e.g., controller updates user's shopping cart).[1]
4. A view uses the model to generate an appropriate user interface (e.g., view produces a screen listing the shopping cart contents). The view gets its own data from the model. The model has no direct knowledge of the view. (However, the observer pattern can be used to allow the model to indirectly notify interested parties – potentially including views – of a change.)
5. The user interface waits for further user interactions, which begins the cycle anew.



Although simple in its immediate construction there are a ton of things that can be cleaned-up and/or automated in MVC to make it even better.

I would think that a PHP Programmer who is very comfortable, particularly with PHP5 (Adding much needed OO characteristics) would be able in many ways to roll there own MVC just from reading this at WiKipedia. But if you're like most programmers you're lazy, in a good way. You don't want to re-invent the wheel so-to-say, and that's why there is a ton of already built frameworks: PHPWACT
Last time I checked this was pretty exhaustive.

I would recommend visiting each of these, and/or googling for some reviews to find which one best fits you and your particular project's needs. You may find Qcodo fits a photography site, but Symfony is better for complex applications.

There are also some good books out there, being an outspoken supporter of PHPArch, I HIGHLY recommend Jason E. Sweat's well-worded contribution and
Harry Fuecks' Book.

I also recommend getting a subscription to PHPArch.

< Prev   Next >
A CovenantEDesign Project.
All Content Copyright © Edward Prevost 2000-2008
Disclaimer: All thoughts and opinions expressed here are not necessarily reflective of Covenant E-design, its employees, clients or affiliates.