-1

I have searched and read about mvc. I understand MVC. I am only stuck on the beginnings. If I can just get that rolling, I'll be alright to continue. But as soon as I get going the writer throws in something they don't explain. Example, they will show a model extends some class, but they never show you that class or don't explain it. I know this has been asked a bunch on SO, but it seems to degrade into complexity too fast.

Is it possible to just have one model, one controller, and one view and show that as an example? Am I making it too simple?

I have looked at various premade frameworks, codeigniter, wigbi, skinnymvc, etc. I do not want to use them right now. I understand OOP and OOD. I just can't put this together for whatever reason. Thanks for anything that shows a model, a controller, a view, one system, three pages, that isn't secretly three gigantic pages that are masquerading as simple, maybe just a select * from users. I am trying to use PDO if that matters.

4

3 回答 3

4

Model is not an object or a class, but a layer. It is one of two layers, other being presentation layer (which contains most notably controllers and views). The simplest example would be something like:

$serviceFactory = new ServiceFactory( $pdo );
$view =           new FooView( $serviceFactory, $pathToTempaltes );
$controller =     new FooController( $view, $serviceFactory );

$controller->someCommand();
$view->produceResponse();

This example assumes extremely simplified model layer, with no abstraction separating domain objects and data abstraction structures.

于 2012-10-12T15:59:32.527 回答
0

Think of it as 3 sheets of paper stacked in front of each other. The front piece of paper (view) shows the user interface, the back piece of paper (model) is getting information from the database, and the middle piece of paper (controller) is relaying information from the back piece of paper to the front piece of paper.

于 2012-10-12T15:57:50.853 回答
0

Simplest possible example. Do not build an application on this.

function model() {
      return array('some'=>'random','prefix'=>'Hello');
}

function view($data) {
      header('content-type: text/html;charset=utf-8');
      echo "<html><head>title</head><body>",htmlspecialchars($data['greeting']),"</body></html>";
}
function controller() {
      $name = $_GET['name'];
      $modeldata = model();
      $viewdata = array('greeting'=> "{$modeldata['prefix']} {$name}");
      view($viewdata);
}

controller();
于 2012-10-12T16:03:47.827 回答