Trying to access array offset on value of type null
Posted 慕斯-ing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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即可解决问题。
以上是关于Trying to access array offset on value of type null的主要内容,如果未能解决你的问题,请参考以下文章
Using pointer to access array instead of index
Trying to get property of non-object
Trying to get property of non-object_thinkphp路由报错
Laravel 避免 Trying to get property of non-object 错误
灯塔阅读 - Scientists Are Trying to Pinpoint the Origin of Mysterious Signals From Outer Space
灯塔阅读 - Scientists Are Trying to Pinpoint the Origin of Mysterious Signals From Outer Space