* [ ] 模板语法对照 (JS CSS中也可以使用,配置文件中设置`@`,则使用`{@$user}`) * [ ] `:`或者`.`开头不使用echo * [ ] `$$`开头对像变量 (`{$$Obj}`解析成`$this->Obj`) * [ ] `$.`开头局部变量(`{$.Obj}`解析成`$Obj`) * [ ] `$`开头模板变量 (`{$Obj}`解析成`$this->obtain('Obj')`) ``` {file='foot.php'} {file=foot.php} {file="foot.php"} {file="foot"} {file=foot} //引入其他模板,这些写法都可以 {$user='administrator'} <?php $this->assign('user','administrator');?>//设置参数 {:dump($user)} <?php dump($this->obtain('user'));?>//使用dump方法,前面加点号代表不使用echo {dump($user,false)} <?php echo dump($this->obtain('user'),false);?>//使用dump方法,前面不加点号代表使用echo {$inttest=2*8+9} <?php $this->assign('inttest',2*8+9);?>//可以这样使用 {$inttest} <?php echo $this->obtain('inttest');?>//输出25 {$$Data='demo'} <?php $this->Data='demo';?>//2个$$代表使用$this {$$Data} <?php echo $this->Data;?> //前面不加点号代表使用echo {.$$Data} <?php $this->Data;?> //前面加点号代表不使用echo {:$$getuserid()} <?php $this->getuserid();?>//2个$$代表使用$this,前面加点号代表不使用echo {$.userid=$$getuserid()} <?php $userid=$this->getuserid();?> //调用方法 {$a.b.c='数组使用'} <?php $this->assign('a.b.c','数组使用');?>//设置数组 {$a.b.c} <?php echo $this->obtain('a.b.c');?>//输出:数组使用 {$.demo='abcd'} <?php $demo='abcd';?>//使用$.开头设置变量 {$.demo} <?php echo $demo;?>//输出变量 {:test($.a,$$b,$c)} <?php test($a,$this->b,$this->obtain('c'));?>//调用方法,前面不要.就echo {$info=test($.a,$$b,$c)} <?php $this->assign('info',test($a,$this->b,$this->obtain('c')));?>//也可以这样 {$.home->aaa(1,2,$hh)} <?php echo $home->aaa(1,2,$this->obtain('hh'));?>//比如home是对像的 {.$.home->aaa(1,2,$hh)} <?php $home->aaa(1,2,$this->obtain('hh'));?>//比如home是对像的 {$self=new Session()} <?php $this->assign('self',new Session());?>//可以New类 {$info=$self->get()} <?php $this->assign('info',$this->obtain('self')->get());?>//调用类方法 {.ps($info)} <?php ps($this->obtain('info'));?>//输出 {.Cookie::set('test','123456',3600)} <?php Cookie::set('test','123456',3600);?>//使用Cookie设置 {$.get=Cookie::get()} <?php $get=Cookie::get();?> {.ps($.get)} <?php ps($get);?>//输出Cookie {.ps(Cookie::get())} <?php ps(Cookie::get());?>//输出Cookie (优化模板后支持写法) {/*注析/} <?php /**注析*/?> {//注析} <?php //注析?> ``` * [ ] function ``` {function test($id) } {/function} {function demo($id) use($config)} {/function} <?php function test($id) {?> <?php }?> <?php function demo($id) use($config){?> <?php }?> ``` * [ ] if elseif ``` {if ($a==2 && $.b!='s' || $$Data->name=='admin')} {elseif ($a==3 && $.b=='s' || $$Data->name!='admin')} {/else} //写法2{else} {/if} //写法2{if} <?php if ($this->obtain('a')==2 && $b!='s' || $this->Data->name=='admin'){?> <?php }elseif ($this->obtain('a')==3 && $b=='s' || $this->Data->name!='admin'){?> <?php }else{?> <?php }?> ``` * [ ] foreach ``` //{foreach arr k v} 可以不要$ 默认$ {foreach $arr $k=>$v} //写法2{foreach $arr $k $v} 写法3 {foreach $arr=$k=$v} //同样可以使用$. $$ {.ps($k)} {.ps($v)} {/foreach} //写法2{foreach} <?php foreach($this->obtain('arr') as $this->TplData['k']=>$this->TplData['v']){?> <?php ps($this->obtain('k'));?> <?php ps($this->obtain('v'));?> <?php }?> {foreach $arr $v} //写法同上 {.ps($v)} {/foreach} <?php foreach($this->obtain('arr') as $this->TplData['v']){?> <?php ps($this->obtain('v'));?> <?php }?> ``` * [ ] for ``` {for $i=0; $i<=10; $i++} //同样可以使用$. $$ {$i} {/for}//写法2{for} <?php for($this->TplData['i']=0; $this->TplData['i']<=10; $this->TplData['i']++){?> <?php echo $this->obtain('i');?> <?php }?> ``` * [ ] switch ``` //同样可以使用$. $$ {switch:$aaa} {case:111} 1 {.break} {case:"ok"} 2 {case:$a} 3 {.break} {default:} 4 {.break} {/switch} <?php switch ($this->obtain('aaa')){?> <?php case 111:?> 1 <?php break;?> <?php case "ok":?> 2 <?php case $this->obtain('a'):?> 3 <?php break;?> <?php default:?> 4 <?php break;?> <?php }?> ```