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 app\common\model\goods;
use app\common\model\BaseModel;
use think\Cache;
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 app\store\controller\goods;
use app\common\model\goods\GoodsSupplierModel;
use app\store\controller\Controller;
use app\store\model\goods\SupplierModel;
use think\Log;
/**
* 供应商
* Class SupplierModel
* @package app\store\controller\goods
*/
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论