thinkphp process and project template deployment steps for the controller invocation template

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.