用thinkphp的大神看过来

smartcoach 2014-12-02 05:09:58
1、求教一个模版问题,volist绑定只接select过来的数组是没问题的,但是我现在的数组为多个一维数组,这个如何绑定,或者解决第二个问题也可以

2、volist绑定select数据,但是有些字段的数据比如说是1,代表的是另外一张表的某个汉字,比如管理员三个字,现在想让前端绑定的时候,对应的字段1转变成对应表的中文,应该如何做?

谢谢拉
...全文
198 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghostwuboy 2014-12-03
  • 打赏
  • 举报
回复

$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)这个源码就知道 怎么用了
smartcoach 2014-12-02
  • 打赏
  • 举报
回复
引用 3 楼 iseagold 的回复:
是怎么样的数组格式? 然后又是要输出成怎样的?

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"
  }
}

ghostwuboy 2014-12-02
  • 打赏
  • 举报
回复
是怎么样的数组格式? 然后又是要输出成怎样的?
smartcoach 2014-12-02
  • 打赏
  • 举报
回复
引用 1 楼 iseagold 的回复:
输出之间,把一位数组处理成二维数组就可以了啊

<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>
大神告诉我怎么处理啊,不止一个一维数组,是多个在前台列表展示
ghostwuboy 2014-12-02
  • 打赏
  • 举报
回复
输出之间,把一位数组处理成二维数组就可以了啊

<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>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧