码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp视图模板

时间:2018-03-19 13:32:59      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:cond   host   htm   index   100%   select   数据   mes   bubuko   

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {  //控制器
    public function index(){
      $s = "hello";
  $arr = array("code"=>"n001","name"=>"汉族"); //数组
$this->assign("name",$s); //注册变量
 $this->assign("arr",$arr); //注册数组变量
$this->show(); //显示页面 } }

index.html

 <div>{$name}</div>
 <div>{$arr.code}</div>  //或者<div>{$arr["code"]}</div>

浏览器输入http://localhost/tp/index.php/Home/Index/index。显示页面:

技术分享图片

从数据库中调取数据:

 1 <?php
 2 namespace Home\Controller;
 3 use Think\Controller;
 4 class IndexController extends Controller {
 5     public function index(){
 6       $db = D("Nation");
 7       $arr = $db->select();
 9       $this->assign("arr",$arr);
10       $this->show();
11     }
12 }

视图:

<body>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>代号</td>
            <td>名称</td>
        </tr>

         <foreach name="arr" item="v">

             <if condition="$v[‘code‘]==‘n001‘"> 
                 <tr style="color: 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>

 

thinkphp视图模板

标签:cond   host   htm   index   100%   select   数据   mes   bubuko   

原文地址:https://www.cnblogs.com/niushuangmeng/p/8568084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!