Mastering Thinkphp3.2.0----built-in Labels

Source: Internet
Author: User

When using the built-in label, be sure to note that Closed-----single label self-closing, Double-label corresponding closure

Tag learning lies in memory and application

A Comparison of Judgments

1 // the full format of the IF statement 2 <if condition= "$user eq ' crayon little New '" >3 small New 4 <ElseIf condition= "$user eq ' Kurosaki '"/>5  6 <else /> 7 Error 8 </if>
1 //PHP functions can be used in condition conditions2<ifCondition= "mb_substr ($user, 0,3, ' UTF-8 ') eq ' crayon Small ' >3 //using dot syntax in condition conditions, intelligently judging arrays or objects4<ifCondition= "$data. User eq ' crayon little new ' >5 //using the colon syntax in the condition condition, use the object directly6<ifCondition= "$data: User eq ' crayon little new ' >7 //using System variables in condition conditions8<ifCondition= "$Think. Get.user eq ' crayon little new ' >

Switch statement

1 // the value of name, like the IF statement, can be a variable, an array, an object, a function, or a system variable 2 <switch name= "user" >3 < case value= "crayon Little new" > Small new </ case >4 < case value= "kurosaki" > One protection </case >5 <default / > error 6 </switch>

By default, case will automatically add a break statement to prevent penetration, and if you just want to penetrate, you can remove the Break. of course, most do not need to set Break.

1 // Remove break 2 <Case break = "0" > Small new </case >

Compare tags, can be paired with else

1 // eq Label 2 <eq name= "user" value= "1" > equal <else/> Unequal </eq>3//  The other tags and the use of the title are basically the same no more than 4//compare Unified Method 5 <compare type= "eq" name= "user" value= "1" > Equal <else/> Unequal </compare>

Range Judgment label in, notin, between, Notbetween

Determine the label of the variable present--notpresent empty--notempty defined--notdefined

In fact, they can be used in conjunction with else, it is said that not* does not have any effect, at least the actual effect of

1<present name= "Think.get.user" >$_get[' User '] assigned </present>2 //determines whether the variable is empty and null outputs3<EmptyName= "user" >user is a null value </Empty>4 //determines whether the variable is empty and is not empty output5<notempty name= "user" >user NOT NULL </notempty>6 //determines whether a variable is empty, combined7<EmptyName= "user" >8 user is a null value9<Else/>Ten user is not a null value one</Empty> a //determine if a variable is empty, system variable -<EmptyName= "Think.get.user" >$_get[' user '] is null value </Empty> - //determines whether a constant is defined, defines the output the<definedName= "app_path" >app_path constant defined </defined> - //determine if a constant is defined, no output is defined -<notdefined name= "app_path" >app_path constant undefined </notdefined> - //determines whether constants are defined, combined +<definedName= "app_path" > - App_path constants are defined +<Else/> a App_path constants Not defined at</defined>

Two Traversing loops volist tags, Foreach labels, and for tags

Volist Label

Basic:

<ul> <volist name= "data" id= "arr" > <li>{$arr. id}--{$arr. user}--{$arr . Mail} </li> </volist> </ul>

PS: the data in Name= "data" here is the controller to the template to define the variables, to correspond;
Arr in id= "arr" is the array name that will traverse the loop and can be Customized.

Various properties:

1 //offset from the beginning of the first, the starting value of 0,length total number of bars2<volist name= "data" id= "arr"offset= "5" length= "ten ">3<li>{$arr. id}--{$arr. user}--{$arr.Mail}</li>4</volist>5 //MoD for the current remainder, the current index divided by 2 more than 1, output even6<volist name= "data" id= "vo"mod= "2">7<eq name= "mod" value= "1" >8<li>{$vo. id}--{$vo. user}--{$vo.Mail}</li>9</eq>Ten</volist> one //use empty to populate without data a<volist name= "data" id= "vo"empty= "no data"> -<li>{$vo. id}--{$vo. user}--{$vo.Mail}</li> -</volist> the //The empty property does not support HTML direct input, but can be output through a variable - $this->assign (' empty ', ' <span style= ' color:red ' > No data </span> '); -<volist name= "data" id= "vo"Empty="$empty"> - //A variable that iterates through the key output +<volist name= "data" id= "vo"key= "k"> -<li>{$k} -- {$vo. id}--{$vo. user}--{$vo.Mail}</li> +</volist> a //No k specified, can also be output with I variable at<li>{$i} -- {$vo. id}--{$vo. user}--{$vo.Mail}</li> - //key variable, You can directly output the index value, starting from 0 -<li>{$key} -- {$vo. id}--{$vo. user}--{$vo.Mail}</li>

foreach Label

The foreach tag is similar to the volist tag except that the foreach tag is simpler and has no additional attributes.

// only the key property is supported, but {$key} variable supports <ul><foreach name= "data" item= "vo" ><ul>{$vo. id} --{$vo. user}</ul></foreach></ul>

The for label is much simpler.

 1  //  from 1 to 99 loop  2  <for  start= "1" end  = ">3  {$ I }<br/>4  </for  >5  //  full form  Span style= "color: #008080" >6  <for  start= "1" end  = "comparison=" lt "step=" 2 "name=" k ">7  { $i }<br/>8  </for ; 

In addition to the start and end must values, there are three optional values. Comparison is greater than or less than, the default value is LT
(<); name is the name of the loop variable, and the default value is I;step is a stepping value, which defaults to 1.

Three Other labels

1 //define variables in the template, value can be a variable ($user) or a system variable ($Think. get.user)2<assign name= "var" value= "123"/>3{$var}4 //define constants in the template, value values can be variables ($user) or system variables ($Think. get.user)5<DefineName= "my_name" value= "Lee"/>6{$Think.Const.my_name}7 import tag can import JS and CSS files intelligently8 //General Introduction Method9<script type= "text/javascript" src= "__public__/js/index.js" ></script>Ten<link rel= "stylesheet" type= "text/css" onehref= "__public__/css/index.css"/> a //using import imports, JS and CSS are directories -<import type= "js"file= "js.index"/> -<import type= "css"file= "css.index"/> the //BasePath Modify the default path by importing with import -<import type= "js"file= "js.index" basepath= "./common"/> - load load tag to load JS and CSS files intelligently - //Load Using load +<load href= "__public__/js/index.js"/> -<load href= "__public__/css/index.css"/> + The system also provides dedicated JS and CSS tags, specifically for loading a //use a dedicated label at<js href= "__public__/js/index.js"/> -<css href= "__public__/css/index.css"/>
1 //Using PHP tags2<php>3 $a= 1;4 $b= 2;5 Echo $a+$b;6</php>7 //using PHP syntax8<?PHP9 $a= 1;Ten $b= 2; one Echo $a+$b; a?> - If you want to output the Label's content as it is, you can use the literal tag - //Output as-is the<literal> -<php>Echo123;</php> -</literal>

Mastering Thinkphp3.2.0----built-in Labels

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.