A Typical MVC request workflow - Raysmond/FDUGroup GitHub Wiki

![a typical MVC request workflow](http://raysmond.com/public/a typical MVC request workflow copy.PNG)


  1. A client user type the URL “http://localhost/FDUGroup/site/welcome/Raysmond” in the browser. Then, index.php will be the first bootstrap file to handle the request.
  2. An application instance will be created and initialize the web application.
  3. The application will invoke the request handler to normalize the process the HTTP request based on the URL.
  4. The application will invoke the router to resolve the URI information. In this example, the result should be: controller ID = “site”, action ID = “welcome” and the parameters array = [“Raysmond”].
  5. The SiteController will be created to handle the current request. An extract action named “actionWelcome” will be invoked automatically and “Raysmond” will the first arg passed to the method.
  6. The controller may obtain data from database via a model.
  7. The action renders the data via view file named “welcome.php” as main content
  8. Some modules(widgets) may be rendered in the layout file(HTML template)
  9. The main content will be inserted into the layout.
  10. Finally, the rendered HTML will be printed, so the user can view the result page

The corresponding code:
controllers/SiteController.php

<?php
class SiteController extends BaseController
{
    public $layout = "index";
    public $defaultAction = "index";

    function actionWelcome($name)
    {
        $this->render("welcome",["name"=>$name]);
    }
}
?>

views/site/welcome.php

<h1>
    Welcome, <?=$name?>
</h1>

The HTML result
result

⚠️ **GitHub.com Fallback** ⚠️