Trying to access array offset on value of type null

报错: 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即可解决问题。

经验分享 程序员 微信小程序 职场和发展