thinkorm 循环问题,

siwei

问题描述

thinkorm 循环问题,

为此你搜索到了哪些方案及不适用的原因

<?php
namespace app\controller;
use support\Request;
use support\Response;
use app\model\Buy;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;
use think\facade\Db;
use support\View;

class IndexController extends Crud
{
    public function index(): Response
    {
        // Webman 使用 ThinkORM 进行查询
        $list = Db::table('fg_buy')
                    ->field('yh, SUM(xse) as total_xse')
                    ->group('yh')
                    // ->order('xse', 'desc')
                    ->limit(10)
                    ->select();
        // View::assign('list',$list);
        // return view( 'index/index');
         return json(['code' => 0, 'msg' => 'ok','data' =>$list]);
    }

}

输出结果:
{"code":0,"msg":"ok","data":[{"yh":8122,"total_xse":"3"},{"yh":8125,"total_xse":"3"},{"yh":8126,"total_xse":"3"},{"yh":8129,"total_xse":"100"},{"yh":8131,"total_xse":"3"},{"yh":8136,"total_xse":"3"},{"yh":8141,"total_xse":"3"},{"yh":8144,"total_xse":"3"},{"yh":8147,"total_xse":"3"},{"yh":8150,"total_xse":"3"}]}

模版循环代码如下:

<tbody>
                        <volist name="list" id="vo">
                            <tr>
                                <td class="am-text-xs ">{:$vo['yh'] }</td>
                                <td class="am-text-xs ">{:$vo['total_xse'] }</td>
                                <!-- <td class="am-text-xs ">
                                    <button class="am-btn am-btn-danger am-btn-xs am-round"
                                        onclick="location.href = '{:U('Zshuihuang/xq',array('id'=>$vo['id']))}';return false;">
                                        详情 </button>
                                </td> -->
                            </tr>
                        </volist>
                    </tbody>

缓存文件如下:
截图
错误如下:
截图
请问各位大咖,这是为什么?
截图

606 2 0
2个回答

xiaoming

打开 生成的php 文件看下 生成的php代码时什么样子的

  • siwei 2024-03-09

    <volist name="list" id="vo">
    <tr>
    <td class="am-text-xs "><?php echo $vo['yh']; ?></td>
    <td class="am-text-xs "><?php echo $vo['total_xse']; ?></td>
    </tr>
    </volist>

  • siwei 2024-03-09

    应该是:{volist name="list" id="vo"}
    {$vo.id}:{$vo.name}<br/>
    {/volist} 以上是thinkphp3.2的做法,解决了

Madman

我怀疑是不是View::assign('list',$list);这里的问题?webman文档里好像没有这种写法

return view( 'index/index', ['list' => $list]); 你改成这样试试

  • siwei 2024-03-09

    模版写成thinkphp3.2时代做法了

×
🔝