tp视图模板
<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { public function index(){ $s = "hello"; $this->assign("name",$s); $this->show(); } }
新建Index文件在这个文件下新建
<!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>{$name}</div> </body> </html>
<div>{ $name}</div>
如果有空格的话就不会替换,会原样输出
<?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> </head> <body> <div>{$name}</div> <div>{$arr["name"]}</div> <div>{$arr.name}</div> </body> </html>
点方法和取索引的方法都可以
从数据库中获取数据展示在前端
<foreach>
<if>
<else/>
</if>
</foreach>
<!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>发放嘎发动发动反攻{a}士大夫撒粉</div> </literal> </body>
这样{a}就不会被解析掉