报错: Trying to access array offset on value of type null
框架: thinkphp5.1+layui
问题分析:
(前台界面)
在这里插入图片描述
在这里插入图片描述
(后端代码)

 //编辑渲染
    public function edit(Request $request)
    {
        $result = RcryModel::get($request->param('bh'));
        $this -> view -> assign('result', $result);
        return $this -> view -> fetch('edit');
    }

(前端代码)

<form class="layui-form">
	<input type="hidden" id="bh" name="bh" autocomplete="off" class="layui-input" value="{$result.bh}" >
</form>
<script>
部分代码如下①:
  {field: 'id', title: 'ID', width: '5%',hide:'true',templet:function(d){return '<div style = "text-align:center">'+d.id+'</div>'},}
部分代码如下②:
    content: ['{:url("Rcry/edit")}?bh=' + data.bh, 'yes'],
</script>            

错误原因: 数据库中rcry表无bh字段,而是id。故而,当点击编辑的时候,无法获取数据表格中的bh信息,$result为空。将前后端传值的bh均改为id即可解决问题。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐