thinkphp in view two, thinkphp view two _php tutorials

Source: Internet
Author: User

View two in thinkphp, thinkphp View II


Views in the Thinkphp

1. Template annotations

In the actual project development, the annotation function is often used, and if it is a thinkphp framework, it can be commented in the template file as follows:

{//comment content}: single-line comment

{/* Comment content */}: Multiline Comment

Example code:

Running the above code shows that the template comment in the thinkphp framework belongs to the service-side comment and does not display the output in the client browser.

2. Fetch template Content

In the actual project development, if we just want to get the template content but not output, then this time can consider using the fetch method to implement.

$this->fetch (): ① loading template ② substitution variable

$this->display (): ① load template ② replace variable ③ output template content

Example code:

3. Variable output

In the thinkphp template engine, you can use the Assign method to assign a variable to a template file and output it, which can be an ordinary variable, an array variable, an object variable, or a variable type.

1) Common variables

In the template, access to it can be achieved through the {$ variable name}:

2) Array variables

① One-dimensional arrays

You can display output in a template in the following ways:

② Two-dimensional arrays

In the template file, you can access it in the following ways:

3) Object variables

In the template file, you can access it in the following ways:

4. System Variables

    • $Think. Server: $_server[]
    • $Think. Get: $_get[]
    • $Think. Post: $_post[]
    • $Think. Request: $_request[]
    • $Think. Cookie: $_cookie[]
    • $Think. Session: $_session[]
    • $Think. config: Reading configuration information from a configuration file

Example code:

Operation Result:

5. Using function (variable adjuster)

Main function: Implement the format operation of the variable, basic syntax:

{$name |fn1|fn2=arg1,arg2,###}

Special note: In the use of functions, it has a special form: # # #代表当前变量本身

Example code:

6. Default value

In the actual project development, a variable is often judged, if it is empty, it will not show anything, but so its experience is not very friendly, so in order to solve this problem, you may want to consider using the default values to set:

{$ variable |default= "default value"}

7. Operators

In some template engines such as smarty, it is not possible to directly participate in mathematical operations. However, in the thinkphp template engine, it is the basic syntax that allows for direct mathematical operations:

    • + {$a + $b}
    • -{$ab}
    • * {$a * $b}
    • /{$a/$b}
    • % {$a% $b}
    • + + {$a + +} or {+ + $a}
    • --{$a--} or {--$a}

Example code:

In the template page, you can use operators to perform mathematical operations on the above two variables:

http://www.bkjia.com/PHPjc/1117676.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117676.html techarticle View two in thinkphp, thinkphp view in two thinkphp View 1, template comments in the actual project development, often to use the annotation function, if it is thinkphp frame, you can in the template ...

  • Related Article

    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.