thinkphp Basic Primer (2)

Source: Internet
Author: User
Tags php programming

The first section describes the thinkphp basic path problem, and the second section describes common uses of thinkphp (M-Layer and V-layer)

We'll start with a new IndexController.class.php on the controller layer (the new file is formatted as xxxController.class.php, with the proposed capitalization), and the framework will not recognize the controller file

Create a new index function

 <? PHP namespace Home\controller;  use   Think\controller;  class  Indexcontroller extends   Controller { public  function   index () {  $this ->assign (' variable ', "Output variable to template"); //        assign is to output the controller's variables to the V-level   $this ->display (); // assign to output to the template }  

Then we add an index folder in the View folder (the name should be the same as the controller name, such as the Aaacontroller controller will create a new AAA folder), Create a new index.html file in index (this name matches the function name of display in the index controller) and enter the following code:
<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>{$variable}</Body></HTML>

{$XXX} This outputs the assign variable in the controller, so we http://localhost/your folder name/index.php?m=home&c=index&a=index in the URL input, The words "Output variable to template" will appear so that the output variable is implemented in the template. This is very common!!

And then the second common place is the U function, I don't say much here. See API documentation

Without the display function is not rendered to the template, can be used to manipulate the logic, and then if the AJAX request an address, the request address is a controller function (reflected in the URL of the A parameter), the other operation is similar to the pure native PHP programming.

thinkphp Basic Primer (2)

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.