TP视图模板

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $s = "hello";
        $this->assign("name",$s);
        $this->show();
    }
}

 

新建Index文件在这个文件下新建  

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
      $s = "hello";
	  $arr = array("Code"=>"n001","Name"=>"汉族");
	  $this->assign("arr",$arr);
	  $this -> assign("name",$s);
	  $this->show(); 
    }
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文件</title>
<style type="text/css">	
		
</style>
</head> 
 
<body> 
  <div>{$name}</div> 
<div>{$arr.Name}</div>  
</body>
   
</html> 

显示:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文件</title>
<style type="text/css">	
		
</style>
</head> 
 
<body> 
<table width="100%" border="1" cellpadding="0" cellspacing
"0">
	<tr>
		<td>代号</td>
		<td>名称</td>
	</tr> 
	<foreach name="arr" item="v">
	<tr>
		<td>{$v.code}</td>
		<td>{$v.name}</td>
	</tr>
	
	</foreach>
	
</table>  
</body>
   
</html>

  

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    $db = D("Nation");
	$arr = $db->select();
	$this->assign("arr",$arr);
	$this->show(); 
    }
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>     
    </head>
     
    <body>
    <table width="40%" border="1" cellpadding="0" cellspacing="0" align="center">
        <tr>
            <td>代号</td>
            <td>名称</td>
        </tr>
        <foreach name="arr" item="v">
         
        <if condition="$v['code']=='n006'">
            <tr bgcolor="red">
                <td>{$v.code}</td>
                <td>{$v.name}</td>
            </tr>
        <else/>
            <tr>
                <td>{$v.code}</td>
                <td>{$v.name}</td>
            </tr>
        </if>
             
         
        </foreach>
    </table>
    </body>
</html>

  

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
       $db = D("Nation");
       $arr = $db->select();
       $this->assign("arr",$arr);
       $this->show();
    }
}

  

php里面的函数在这里几乎都能用比如时间戳转化成能看懂的时间格式

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){;
       $this->assign("d","134212534");;
    }
}

 {$d|date="Y-m-d H:i:s",###}   {变量名|函数名,参数,参数}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>     
    </head>
     
    <body>
    <div>{$d|date="Y-m-d H:i:s",###}</div>
     
    </body>
</html>

  

<literal></literal>

<literal>
    <div>你是看见你手机看{b}士大夫撒粉</div>
</literal>
    </body>

  

 这样{b}就不会被解析掉

 

posted @ 2018-03-15 17:00  小孩坏坏  阅读(136)  评论(0编辑  收藏  举报