简体   繁体   中英

Simple MVP example with PHP

I know how to work with the MVC model, but I don't have an idea how to work with MVP. I read about the differences between them but don't know how to accomplish it.

The difference is twofold:

  • view is passive and unaware of model
  • presenter (controller) changes state of model, reads information and passes it to view

public function showUsers()
{
    // -- snip
    $data = $accountManager->getUserDetails($from = 10, $to = 20);
    $view->bind('list', $data);
    // -- snip
}

This would be a simplified example of presenter's method. Here is an old answer, briefly explaining the differences between MVC-like patterns used in php.

The MVP pattern is commonly used in event-driven development and evidently there are some PHP frameworks which supports this paradigm. Here is another Stackoverflow question from a couple of years ago that may help get you pointed in the right direction:

Does PHP supports MVP pattern?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM