21,886
社区成员
发帖
与我相关
我的任务
分享
$arr = array (
'0' => array(
'id' => 1,
'username' => 'admin'
),
'1' => array(
'id' => 2,
'username' => 'admin2'
)
);
$this->assign("list",$arr);
========模板引用==================
<volist name="list" id="vo">
{$key}---{$vo.id}---{$vo.username}<br/>
<volist name="vo" id="sub">
{$key} ----- {$sub}<br/>
</volist>
</volist>
=================模板编译结果=====================
<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i; echo ($key); ?>---<?php echo ($vo["id"]); ?>---<?php echo ($vo["username"]); ?><br/>
<?php if(is_array($vo)): $i = 0; $__LIST__ = $vo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$sub): $mod = ($i % 2 );++$i; echo ($key); ?> ----- <?php echo ($sub); ?><br/><?php endforeach; endif; else: echo "" ;endif; endforeach; endif; else: echo "" ;endif; ?>
===============输出结果================
0---1---admin
id ----- 1
username ----- admin
1---2---admin2
id ----- 2
username ----- admin2
Thinkphp的模板用的是PHP流程控制的替代语法
模板源码:Library->Think->Template->Taglib->Cx.class.php, 你看public function _volist($tag,$content)这个源码就知道 怎么用了
public function index() {
$m = M('Manger');
$arr = $m->select();
foreach ($arr as $v) {
if ($v['is_lock'] == 1) {
$v['is_lock'] = '启用';
} else {
$v['is_lock'] = '禁用';
}
if ($v['role_id'] != 0) {
$r = M('Role');
$arry = $r->where('id=' . $v['role_id'])->select();
$v['role_id'] = $arry[0]['Rolename'];
}
$arr1 = $v;
}
$this->assign('list', $arr1);
$this->display();
}
这里,只接select的话就volist绑定就好了,我循环去替换了两个字段,一个就是是否锁定,一个是换了用户的角色中文名,
替换万结果出来的就是
array(8) {
["id"]=>
string(2) "10"
["username"]=>
string(6) "admin2"
["userpwd"]=>
string(32) "e10adc3949ba59abbe56e057f20f883e"
["datetime"]=>
string(19) "2014-12-02 02:24:06"
["role_id"]=>
string(1) "1"
["role_type"]=>
NULL
["telephone"]=>
string(3) "123"
["is_lock"]=>
string(6) "鍚敤"
},
array(8) {
["id"]=>
string(2) "11"
["username"]=>
string(6) "admin2"
["userpwd"]=>
string(32) "e10adc3949ba59abbe56e057f20f883e"
["datetime"]=>
string(19) "2014-12-02 02:24:06"
["role_id"]=>
string(1) "1"
["role_type"]=>
NULL
["telephone"]=>
string(3) "123"
["is_lock"]=>
string(6) "鍚敤"
}
不替换只接能volist的应该是
array(2) {
[0]=>
array(8) {
["id"]=>
string(1) "9"
["username"]=>
string(5) "admin"
["userpwd"]=>
string(32) "e10adc3949ba59abbe56e057f20f883e"
["datetime"]=>
string(19) "2014-12-02 12:18:13"
["role_id"]=>
string(1) "9"
["role_type"]=>
NULL
["telephone"]=>
string(3) "123"
["is_lock"]=>
string(1) "1"
}
[1]=>
array(8) {
["id"]=>
string(2) "10"
["username"]=>
string(6) "admin2"
["userpwd"]=>
string(32) "e10adc3949ba59abbe56e057f20f883e"
["datetime"]=>
string(19) "2014-12-02 02:24:06"
["role_id"]=>
string(1) "8"
["role_type"]=>
NULL
["telephone"]=>
string(3) "123"
["is_lock"]=>
string(1) "1"
}
}
<table width=100% style="border:1px solid #ccc; text-align:left;">
<volist name="article_list" id="vo">
<tr>
<td>标题:</td>
<td><input type="text" id="article_title_edit" name="article_title_edit" value="{$vo.title}"/></td>
</tr>
<input type="hidden" name="article_id_edit" id="article_id_edit" value="{$vo.id}" />
<input type="hidden" name="article_cate_edit" id="article_cate_edit" value="{$vo.cate_id}" />
<tr>
<td>内容:</td>
<td><textarea id="article_content_edit" name="article_content_edit">{$vo.content}</textarea></td>
</tr>
<tr>
<td>标签:</td>
<td><input type="text" name="article_tags_edit" id="article_tags_edit" value="{$vo.tags}"/></td>
</tr>
<tr>
<td>文章分类:</td>
<td>
<select name="category_list_edit" id="category_list_edit">
<option>请选择分类</option>
<option value="1">根类</option>
<volist name="all_cate" id="cvo">
<if condition="($cvo['id'] eq $vo['cate_id'])">
<option value="{$cvo.id}" selected>{$cvo.category_name}</option>
<else />
<option value="{$cvo.id}">{$cvo.category_name}</option>
</if>
</volist>
</select>
</td>
</tr>
<tr>
<td>已上传图片:</td>
<td>
<img src="__ROOT__{$vo.images}" />
</td>
<input type="hidden" name="article_images_edit" id="article_images_edit" value="__ROOT__{$vo.images}" />
</tr>
<tr>
<td>图片上传:</td>
<td>
<input type="file" name="article_images_upload" id="article_images_upload" value=""/>
</td>
</tr>
<tr>
<td>推荐到首页?</td>
<td>
<if condition="$vo.is_recommand eq 1">
<input type="radio" name="article_show_index_edit" value="{$vo.is_recommand}" checked/>是
<input type="radio" name="article_show_index_edit" value="0" />否
<else />
<input type="radio" name="article_show_index_edit" value="1" />是
<input type="radio" name="article_show_index_edit" value="{$vo.is_recommand}" checked/>否
</if>
</td>
</tr>
<tr>
<td>是否显示:</td>
<td>
<if condition="$vo.is_show eq 1">
<input type="radio" name="article_show_edit" value="{$vo.is_show}" checked/>是
<input type="radio" name="article_show_edit" value="0" />否
<else />
<input type="radio" name="article_show_edit" value="1" />是
<input type="radio" name="article_show_edit" value="{$vo.is_show}" checked/>否
</if>
</td>
</tr>
</volist>