PHP MVC
Moderator: General Moderators
Yesterday I came across these (3) "More Stupidly Easy MVC in PHP" http://codesnipers.com/?q=node/233&title=
Another good explanation I found is on phppatterns:
part 1 http://www.phppatterns.com/docs/design/ ... er_pattern
part 2 http://www.phppatterns.com/docs/design/ ... _version_2
If you find some good resources yourself please let me know, as I'm looking into these patterns as well. Never know what brilliant writings I'm missing.
part 1 http://www.phppatterns.com/docs/design/ ... er_pattern
part 2 http://www.phppatterns.com/docs/design/ ... _version_2
If you find some good resources yourself please let me know, as I'm looking into these patterns as well. Never know what brilliant writings I'm missing.
-
cokacolarolla
- Forum Newbie
- Posts: 1
- Joined: Fri Feb 10, 2006 12:53 am
- Contact:
Heres an onlamp article http://www.onlamp.com/pub/a/php/2005/09 ... intro.html
also found this gather detailed introduction from php.MVC: http://www.phpmvc.net/docs/guides/guide ... -101#INTRO
also found this gather detailed introduction from php.MVC: http://www.phpmvc.net/docs/guides/guide ... -101#INTRO
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
The Model-View-Controller (MVC) Design Pattern for PHP by Tony Marston.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You can read lots of articles on MVC and still not get to the heart of it with regards to a PHP implementation. MVC is a very high level and slightly vague pattern -- which makes it different from most of the other common pattern which are much more specific.
The strangest thing about MVC is that although it is about three components, there are only two separations. And MVC is mainly about separations and dependencies. The reason that there are only two separations is that the View and the Controller are in the same level -- the Presentation.
So the basic separation is the following where Presentation is dependent on the Model, but the Model is independent of the Presentation:I should note that if you simply implement this separation (between the code that provides the data and the code that displays it) then you have 95% of the benefits of MVC. This Model/Presentation separation is the most important thing that programmers can achieve to produce better appliction code.
After that major separation there is the View / Controller separation. This is the fun part to code and it is the center of most of the discussion about MVC. However there is no agreement on where the dividing line between the two should be drawn or what dependencies there should be. In many cases it is implementation specific.
The classic form has the View dependent on the Controller like this:Classic MVC code might look something like this:PS - I would be wary of many of the articles listed. If it is PHP specific discussion I would check the source and how old the information is. Non-PHP discussions (e.g. Martin Fowler) might just confuse, but you can also get some sense of the bigger picture.
The strangest thing about MVC is that although it is about three components, there are only two separations. And MVC is mainly about separations and dependencies. The reason that there are only two separations is that the View and the Controller are in the same level -- the Presentation.
So the basic separation is the following where Presentation is dependent on the Model, but the Model is independent of the Presentation:
Code: Select all
Presentation
|
V
ModelAfter that major separation there is the View / Controller separation. This is the fun part to code and it is the center of most of the discussion about MVC. However there is no agreement on where the dividing line between the two should be drawn or what dependencies there should be. In many cases it is implementation specific.
The classic form has the View dependent on the Controller like this:
Code: Select all
View -> Controller
(Presentation)
|
V
ModelCode: Select all
class MyModel() {
function getName()
function getAddress()
}
class MyView {
function render($model) {
$template = new Template('mytemplate.php');
$template->set('name', $model->getName());
$template->set('address', $model->getAddress());
return $template->render();
}
}
class MyController {
function execute($request, $response) {
$model = new MyModel();
$view = new MyView($model);
$response->setContent($view->render());
}
}
$controller = new MyController($request, $response);
$response->out();(#10850)