Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

Thinkphp-5 Cache::tag paginate返回的对象,出现找不到id的错误

create table

CREATE TABLE yoshop_goods_supplier (
  supplier_id INT(11) unsigned PRIMARY KEY auto_increment COMMENT '供应商id',
  NAME VARCHAR ( 255 ) NOT NULL COMMENT '名称',
  brief VARCHAR ( 255 ) COMMENT '简介',
  remarks VARCHAR ( 255 ) COMMENT '备注',
  `sort` INT ( 11 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '排序方式(数字越小越靠前)',
  `wxapp_id` INT ( 11 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '小程序id',
  `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '软删除',
  `create_time` INT ( 11 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` INT ( 11 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间' 
)

create model

<?php

namespace appcommonmodelgoods;

use appcommonmodelBaseModel;
use thinkCache;

class GoodsSupplierModel extends BaseModel {
  protected $name = "goods_supplier";


  public function getList() {
    $key = $this->name . '_' . static::$wxapp_id;
    if (!Cache::get($key)) {
      $query = ['query' => request()->request()];
      $data = $this->where('is_delete', '=', 0)
        ->order(['sort' => 'asc', 'create_time' => 'desc'])
        ->paginate(15, false, $query);
      //return $data;
      Cache::tag('cache')->set($key, $data);
    }
    return Cache::get($key);
  }
}

create controller

<?php

namespace appstorecontrollergoods;
use appcommonmodelgoodsGoodsSupplierModel;
use appstorecontrollerController;
use appstoremodelgoodsSupplierModel;
use thinkLog;

/**
 * 供应商
 * Class SupplierModel
 * @package appstorecontrollergoods
 */
class Supplier extends Controller {
  public function index(){
    $goodsSupplierModel = new GoodsSupplierModel();
    $list = $goodsSupplierModel->getList();
    $html = $this->fetch("index", compact("list"));
    return $html;
  }
}

create view if和fore循环展示ide数据

<div class="am-scrollable-horizontal am-u-sm-12">
  <table width="100%" class="am-table am-table-compact am-table-striped
               tpl-table-black am-text-nowrap">
    <thead>
    <tr>
      <th>ID</th>
    </tr>
    </thead>
    <tbody>
    <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
      <tr>
        <td class="am-text-middle"><?= $item['supplier_id'] ?></td>
       
    <?php endforeach; else: ?>
      <tr>
        <td colspan="11" class="am-text-center">暂无记录</td>
      </tr>
    <?php endif; ?>
    </tbody>
  </table>
</div>

但是测试遇到下面的错误

{
  "msg": "property not exists:app\common\model\goods\GoodsSupplierModel->supplier_id",
  "code": 0
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...