第四节课 skymvc模板的使用

skymvc官方教学课程

第4课 skymvc模板的使用

/**********

*大家好,今天给大家讲讲skymvc的View。

*我们继续从hello world 开始。

*模板目录文件位于themes/index/hello/ themes/wap/hello/目录下 

*模板的命名规范是 $control/$action.html 

 

*/

模板规范结构:规范的意义在于好管理,让别人容易接手。 

<!doctype html>

<html>

{include file="head.html"}

 

<body>

{include file="header.html"}

<div class="main-body">

 

</div>

{include file="footer.html"}

</body>

</html>

 

本课程简单介绍常用的模板语法,更详细的去看手册。

1.模板赋值

<?php 
	$this->smarty->goassign("str",$str)
	$this->smarty->assign(array(
		"data"=>$data
	));
	
	$this->smarty->display("hello/default.html");
?>

 

view.html

<!doctype html>
<html>
{include file="head.html"}

<body>
{include file="header.html"}
<div class="main-body box960">
	<div>说明:用大括号{}替换中括号</div>
	<div>str:{$str}</div>
    
    <div>array:{$arr|print_r}
    	<br>
        <h3>foreach语法</h3>
        {foreach  from=$arr item=v key=k  name=foo }
         {$k}:{$v} index:{$smarty.foreach.foo.index} k+1:{$k+1} k*2:{$k*2}
         {if $smarty.foreach.foo.first}第一条{/if}
         {if $smarty.foreach.foo.last}最后一条{/if}
         {if $k+2>3}k>=1{/if}
         {if $k*2==6}k==3{/if}
         {if $k%3==1}k==1{/if}
         {if $k gte 2} k>=2{/if}
         <br>
        {/foreach}
    </div>
    <h3>if语法</h3>
    <pre>
    //基础
        if($a*2>3){
            a
        }elseif($b){
            b
        }else{
            c
        }
       	if中的表达式
        	if($a) if(!$a)
        	if($a=='a') if($a==0)
            加入计算 + - * / % 
            if($a+1>1) if($a*1>1)
             
        //判断方法
        == eq相等,
         
        !=  neq不相等,
         
        > gt大于,
         
        < lt小于,
         
        >= gte、ge大于等于,
         
        <= lte、le 小于等于,
    </pre>
    
    <h3>数学扩展</h3>
    <div> [math equation="x+y*z/s" x="1" y="2" z="3" s="4" ]={math equation="x+y*z/s" x="1" y="2" z="3" s="4"} [] </div>
    <h3>函数扩展</h3>
    <pre>
    例 fun($str,a,b)
    {$str|fun:a:b}
    1.字数截取 cutstr($string, $length, $dot = ' ...')
    [$str|cutstr:18:...]
    
    2.时间格式化date
    2016-03-29 12:12:112
    [$dateline|date:Y-m-d H:i:s]
    
    3.timeago 多久之前
    5分钟前
    [$dateline|timeago]
    </pre>
    <h3>get方法</h3>
    <div>
    	get调用数据 对应的是model的方法
        
     {get data=getdata model=hello fun=idlist(array())}
     {foreach item=c key=k from=$getdata}
    	{$k}. id:{$c.id} {$c.title}<br>
     {/foreach}
    </div>
    <h3>api方法</h3>
    <div>
    	api调用数据 对应的是ctrl的方法
    	{api data=apidata control=hello fun=api() }
        {get data=apidata model=hello fun=select()}
     {foreach item=c from=$apidata}
     {$c.title}<br>
     {/foreach}
        
    </div>
</div>
{include file="footer.html"}
</body>
</html>

 

转载于:https://my.oschina.net/lrjxgl2/blog/680107

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值