TP6模型里出现Serialization of 'Closure' is not allowed

浏览:1170 发布日期:2020/03/24 分类:ThinkPHP6专区
定义了一个模型public function getUrlAttr($value,$data){
        return $value = strpos($value,'http') === false?url($value):$value;
}
public function getList($where=[],$field='*'){
        $menu = $this->where($where)->field($field)->order('order_id asc')->select()->toArray();
        return $menu;
    }
    /**
     * 有效的菜单缓存
     */
    public function setCache(){
        //获取有效的菜单
        $menu = $this->getList(['status'=>1]);
        echo serialize($menu);
        exit;
        //启动缓存
        cache('admin_menu',$menu);
        return $menu?$menu:[];
    }
出现Serialization of 'Closure' is not allowed这个错误,如果我注释了getUrlAttr这个方法就不会有问题了,明明是用toArray()转成数组了,为什么还报错呢?
最佳答案
评论( 相关
后面还有条评论,点击查看>>