ThinkPHP關於模板的一些嵌套、IF判斷使用

> ##### 前言,如今有一組數據(涉及到3個數據表,order訂單表,order_process辦理流程表,process_status流程描述表),根據當前訂單,展現相應信息

1.辦理流程部分數據:

image

2.流程狀態部分數據:

image

3.指望達到效果以下:

image


這裏就須要用到幾個部分的技巧結合php

通常的循環嵌套使用
<volist name="list" id="vo">
    <volist name="vo['sub']" id="sub">
        {$sub.name}
    </volist>
</volist>

其中第二個volist的name屬性,也能夠寫做name="vo.sub"html

IF判斷使用

經常使用的判斷中,不容許使用<,>,=之類的符號,改成:ajax

標籤 含義
eq或者equal 等於
neq或者notequal 不等於
gt 大於
egt 大於等於
lt 小於
elt 小於等於
heq 恆等於
nheq 不恆等於
1. <eq name="name" value="value">value</eq>

比較標籤中的變量能夠支持對象的屬性或者數組,甚至能夠是系統變量,例如: 當vo對象的屬性(或者數組,或者自動判斷)等於5就輸出json

2 .<eq name="vo.name" value="5">
   {$vo.name}
   </eq>
3.  <!-- 附加說明 判斷數組大小-->
    <if condition="count($vo['additional']) gt 1">
        附加說明:
        <else /> other Framework
    </if>
4.  <!-- 附加說明 判斷數組大小-->
    <if condition="strlen($vo['additional']['0']) gt 1">
        附加說明:
        <else /> other Framework
    </if>

參考php數組

public function orderDetail($id, $userId) {
        $param['id'] = $id;
        $order = M('reorder')->where($param)->find();
        //0.更新訂單被查看的信息:查看人、查看時間
        $watch['userId'] = $userId;
        $watch['posttime2'] = time();
        M('reorder')->where($param)->save($watch);

        //獲取當前項目的默認辦理流程
        $where['projectid'] = $order['projectid'];
        $immiprogram = M('reimmiprogram')->where($where)->find();
        $orderStatus = M('reorderstatus')->where($where)->find();
        $orderStatus['status'] = explode('|',$orderStatus['status']);

        //查找已經完成的辦理流程
        $param_process['orderid'] = $order['orderid'];
        $param_process['isfinish'] = 'true';
        $status1 = M('reorderprocess')->where($param_process)->order('posttime')->select();
        //根據當前訂單狀態,分割orderStatus
        $param_process['isfinish'] = 'false';
        $status2 = M('reorderprocess')->where($param_process)->order('posttime')->select();
       //$this->ajaxJSON($status2);
        //判斷附加說明,是否含分隔符
        foreach ($status1 as $key => &$value) {
            $value['additional'] = explode("|",$value['additional']);
        }

        foreach ($status2 as $key => &$item) {
            $item['additional'] = explode("|",$item['additional']);
        }
        //$this->ajaxJSON($status1);

        $status3 = array();
        $least = count($status1)+count($status2);
        foreach ($orderStatus['status'] as $key => $value) {
            //當前正在辦理的事項
            if($key > $least){
                array_push($status3,$value);
            }
        }
        //查找最新的流程附加信息
        $param_newest['orderid'] = $order['orderid'];
        $process_newest = M('reorderprocess')->where($param_newest)->order('posttime desc')->find();

        $counts = array();
        array_push($counts,0);
        array_push($counts,count($status1));
        array_push($counts,count($status1)+count($status2));
        $this->assign('order',$order);
        $this->assign('immiprogram',$immiprogram);
        $this->assign('orderStatus',$orderStatus);
        $this->assign('process_newest',$process_newest);
        $this->assign('status1',$status1);
        $this->assign('status2',$status2);
        $this->assign('status3',$status3);
        $this->assign('counts',$counts);

        $this->display();
    }

參考json數據status1post

[
    {
        "id": "135",
        "orderid": "2017YH1001",
        "status": "簽約",
        "isfinish": "true",
        "additional": [
            "客戶上門拜訪簽約的"
        ],
        "posttime": "1491321600",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-05-10 14:37:08",
        "create_time": "2017-04-05 00:00:00"
    },
    {
        "id": "136",
        "orderid": "2017YH1001",
        "status": "繳納服務費",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1491321600",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-05 00:00:00",
        "create_time": "2017-04-05 00:00:00"
    },
    {
        "id": "137",
        "orderid": "2017YH1001",
        "status": "提交移民信息表",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1491408000",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-06 00:00:00",
        "create_time": "2017-04-06 00:00:00"
    },
    {
        "id": "138",
        "orderid": "2017YH1001",
        "status": "收集材料",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1491408000",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-06 00:00:00",
        "create_time": "2017-04-06 00:00:00"
    },
    {
        "id": "139",
        "orderid": "2017YH1001",
        "status": "材料製做",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1491408000",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-06 00:00:00",
        "create_time": "2017-04-06 00:00:00"
    },
    {
        "id": "149",
        "orderid": "2017YH1001",
        "status": "遞交申請",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1491753600",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-10 00:00:00",
        "create_time": "2017-04-10 00:00:00"
    },
    {
        "id": "150",
        "orderid": "2017YH1001",
        "status": "得到檔案編號",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1492012800",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-04-13 00:00:00",
        "create_time": "2017-04-13 00:00:00"
    },
    {
        "id": "151",
        "orderid": "2017YH1001",
        "status": "已補件到香港入境處",
        "isfinish": "true",
        "additional": [
            "2017.02.27 補錄資料",
            "2017.03.24 補錄資料 "
        ],
        "posttime": "1493827200",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-05-10 13:45:48",
        "create_time": "2017-05-04 00:00:00"
    },
    {
        "id": "152",
        "orderid": "2017YH1001",
        "status": "已補入資料",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1494432000",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-05-11 00:00:00",
        "create_time": "2017-05-11 00:00:00"
    },
    {
        "id": "153",
        "orderid": "2017YH1001",
        "status": "得到原則性批准信",
        "isfinish": "true",
        "additional": [
            ""
        ],
        "posttime": "1502208000",
        "recorder": "Candy",
        "checkinfo": "true",
        "update_time": "2017-05-10 14:43:03",
        "create_time": "2017-08-09 00:00:00"
    }
]

參考htmlthis

<li class="descriptionDetailList">
    <ul class="descriptionUl1">
        <volist name="status1" id="vo">
            <li class="clearfix">
                <h5 class="finishedH5">{$counts['0']+$key+1}</h5>
                <div class="finishedSchedule">
                    <p>{$vo.status}</p>
                    <span>完成時間:{$vo.posttime|date="Y-m-d",###}</span>
                    <!-- 附加說明 判斷數組大小-->
                    <if condition="strlen($vo['additional']['0']) gt 1">
                        <p><span>附加說明:</span></p>
                        <else />
                    </if>
                    <volist name="vo.additional" id="vo2">
                         <span>{$vo2}</span> <br/>
                    </volist>
                </div>
                <span class="finished">【完成】</span>
            </li>
        </volist>

        <volist name="status2" id="vo">
            <li class="clearfix">
                <h5 class="underwayH5">{$counts['1']+$key+1}</h5>
                <div class="underwaySchedule">
                    <p>{$vo.status}</p>
                    <span>進行中......</span>
                    <!-- 附加說明 判斷數組大小-->
                    <if condition="strlen($vo['additional']['0']) gt 1">
                        <p><span>附加說明:</span></p>
                        <else />
                    </if>
                    <volist name="vo.additional" id="vo2">
                        <span>{$vo2}</span> <br/>
                    </volist>
                </div>
                <span class="underway">【詳情】</span>
            </li>
        </volist>

        <volist name="status3" id="vo">
            <li class="clearfix">
                <h5 class="beforeH5">{$counts['2']+$key+1}</h5>
                <div class="beforeSchedule">
                    <p>{$vo}</p>
                    <span>未開始</span>
                </div>
                <span class="before">......</span>
            </li>
        </volist>

    </ul>
</li>
相關文章
相關標籤/搜索