tp5.0.21模型中执行setInc自增报错

浏览:1781 发布日期:2018/09/28 分类:ThinkPHP5专区
我写的代码,在模型中有一个方法如下:public function addHits($pano_id)
    {
        $this->where('id','=',$pano_id);
        $this->setInc('hits');
    }
实际运行报错如下:[8] ErrorException in Model.php line 1291
未定义数组索引: hits

        public function setInc($field, $step = 1, $lazyTime = 0)
        {
            // 更新条件
            $where = $this->getWhere();

            $result = $this->getQuery()->where($where)->setInc($field, $step, $lazyTime);
            dump($result);
            dump($this->data);
            if (true !== $result) {
                $this->data[$field] += $step;
            }

            return $result;
        }

        /**
         * 字段值(延迟)增长
         * @access public
         * @param string  $field    字段名
打印报错中显示的代码,result,得到结果1(并非true)
打印报错中先死的代码,data,得到空数组.int(1)

array(0) {
}
实际上数据库已经更新了,我把if($result)的代码注释掉,就正常运行了,不知道是否有其他坑.
这是怎么回事.
请问其他人有这个问题吗
最佳答案
评论( 相关
后面还有条评论,点击查看>>