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)
- 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.
- An application instance will be created and initialize the web application.
- The application will invoke the request handler to normalize the process the HTTP request based on the URL.
- 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”].
- 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.
- The controller may obtain data from database via a model.
- The action renders the data via view file named “welcome.php” as main content
- Some modules(widgets) may be rendered in the layout file(HTML template)
- The main content will be inserted into the layout.
- 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