• tp视图模板


    <?php
    namespace HomeController;
    use ThinkController;
    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 HomeController;
    use ThinkController;
    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 HomeController;
    use ThinkController;
    class IndexController extends Controller {
        public function index(){
           $db = D("Nation");
    	   $arr = $db->select();
    	   $this->assign("arr",$arr);
    	   $this->show();
        }
    }
    

     

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

    <?php
    namespace HomeController;
    use ThinkController;
    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}就不会被解析掉

  • 相关阅读:
    高斯消元法求逆矩阵
    二分法
    Boost库
    sorts
    排序算法_HeapSort
    粒子系统之概述_20140101
    新年祝福!_20140101
    思维_逆向的魅力2_20131229
    思维_逆向的魅力_20131229
    编码能力的提升?_20131228
  • 原文地址:https://www.cnblogs.com/navyouth/p/8567023.html
Copyright © 2020-2023  润新知