view层
<?php
require "../libs/Smarty.class.php";
require "abc.php";
$smarty = new Smarty();
$smarty -> setTemplateDir("../tpls");
$smarty -> setCompileDir("../coms");
$smarty -> assign("title","速评表");
//打这个json数据累死我了
$result = '{
"service_type": "car",
"view": {
"info": {
"tag_name": "基本信息",
"data": {
"car_jigou": {
"explain": "合作机构",
"type": "text",
"options": "",
"value": "合作机构A"
},
"car_contract": {
"explain": "合同类型",
"type": "text",
"options": "",
"value": "类型B"
},
"car_chexing": {
"explain": "车型",
"type": "text",
"options": "",
"value": "豪华"
},
"car_brand": {
"explain": "品牌",
"type": "text",
"options": "",
"value": "宝马"
},
"car_xinghao": {
"explain": "型号",
"type": "text",
"options": "",
"value": "740li"
},
"car_licheng": {
"explain": "行驶里程",
"type": "text",
"options": "",
"value": "123456"
},
"car_pailiang": {
"explain": "排量",
"type": "text",
"options": "",
"value": "4.0"
},
"car_color": {
"explain": "车身颜色",
"type": "text",
"options": "",
"value": "A123456"
},
"car_number": {
"explain": "车牌号",
"type": "text",
"options": "",
"value": "京A123456"
},
"car_chejiahao": {
"explain": "车架号",
"type": "text",
"options": "",
"value": "adadg123333"
},
"car_chuchang": {
"explain": "出厂日期",
"type": "text",
"options": "",
"value": "2013.11"
},
"car_chudeng": {
"explain": "初登日期",
"type": "text",
"options": "",
"value": "2015.3"
},
"car_yuanjia": {
"explain": "抵押物原价",
"type": "text",
"options": "",
"value": "70.8"
},
"car_gujia": {
"explain": "抵押物估价",
"type": "text",
"options": "",
"value": "65.5"
},
"car_jianyijiekuan": {
"explain": "合作机构建议借款",
"type": "text",
"options": "",
"value": "60.3"
}
}
}
}
}';
$decode = json_decode($result,true); //变成数组了
$data=array();
foreach($layout as $key=>$kuai){
$datakuai=array();
$temp=$decode['view'][$key];
foreach($kuai as $hang){
$datahang=array();
foreach($hang as $lie){
$a=$temp['data'];
$datahang[$a[$lie]['explain']]=$a[$lie]['value'];
}
array_push($datakuai,$datahang);
//$datakuai.push($datahang);
}
$data[$temp['tag_name']]=$datakuai;
//$data.push($datakuai);
}
$smarty -> assign("mycontent2",$data);
// $smarty -> assign("mycontent2",["速评表详情"=>[["合作机构"=>"abc","合同类型"=>"efg"],
// ["车型"=>"豪华","品牌"=>"宝马","型号"=>"740li","行驶里程"=>"21564"],["排量"=>"3.0l","车身颜色"=>"白色","车牌号"=>"京A54445","车架号"=>"213435435asdw"],
// ["出厂日期"=>"2014.11","初登日期"=>"2015.4"]],
// "议价"=>[["抵押物原价"=>"70","抵押物评估价"=>"65","合作机构建议借款"=>"67"]]]);
// $smarty ->assign("mycontent",$arr);
// $smarty-> assign("id",["name","job","kind","address","skill1","skill2","skill3","skill4","name","job","kind","address","skill1","skill2","skill3","skill4"]);
$smarty -> display("test.tpl");
tpl模板
<html>
<head>
<title>{$title}</title>
<link href="/loan_oa/web/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/loan_oa/web/css/mystyle.css">
</head>
<body>
{$index=0}
<div class="infowrap clearfix">
<div class="infoleft">
{foreach $mycontent2 as $c=>$mycontent}
<div class="infoblock mgt">
<h3>{$c}</h3>
<table class="table">
{foreach $mycontent as $content}
{$length=(24-count($content)*2)/count($content)}
<tr>
{foreach $content as $a=>$b}
<td class="bggray" colspan="3">{$a}</td>
<td colspan="{$length}" >{$b}</td>
{$index=$index+1}
{/foreach}
</tr>
{/foreach}
</table>
</div>
{/foreach}
</div>
</div>