Now in the mainstream MVC framework site, when the controller receives a page request, the corresponding template is usually called, and after the template is rendered, the content is returned to the foreground page, such as a controller in thinkphp:
shop/home/controller/usercontroller.class.php
<?php namespace Home\controller;use think\controller;class Usercontroller extends Controller {//Login event, function default pub LIC, so do not add public also line function login () {//Call template $this, display (); } function register () {echo ' registering '; }}
the above display () inherits from the Controller class, which is called when the The shop/home/view/user/login.html file is returned to the front end and generates an error if the file does not exist.
login.html and other template files, integration with the project steps:
1. The introduction of static code, that is, the login.html file, put into shop/home/view/user/Directory
2. Introduction of CSS, image, JS
A. Above 3 things, the browser needs to send a separate HTTP request
B. When introducing CSS, use the user controller flag as the current directory, obviously not
The absolute path to death is not conducive to post-maintenance, for example, where the directory has been modified, it will be all modified, there are many repetitive work
after optimization: The path is defined by the constant, and only one constant is maintained at a later stage.
3. Set CSS, IMG, and JS paths to constants at the portal file location
4. Get specific CSS, IMG and other file information through constants in the template (all template files are replaced)
5. Set the image path of the CSS file itself correctly (the CSS file refers to the picture)
Define constants in the index.php of the site to ensure that all directories are available
<?php//defines the CSS, IMG, JS constant define ("Site_url", "http://web.1116.com");d efine ("Css_url", Site_url. " shop/public/css/");d efine (" Img_url ", Site_url." shop/public/img/") define (" Js_url ", Site_url." shop/public/js/")
How to use the template HTML:
<link href= "{$Think. Const.cssurl}style.css" rel= "stylesheet" type= "Text/css"/>
thinkphp process and project template deployment steps for the controller invocation template