tp5不能用空模型的解决方法

浏览:1427 发布日期:2018/04/02 分类:功能实现
用惯了TP3的空模型,需要写模型文件也可以用,TP5居然必须要写模型文件,为了解决这个问题,修改了一下助手函数。
在助手函数文件中,修改model函数。代码如下:function model($name = '',$softdeletet = null, $layer = 'model', $appendSuffix = false)
    {
        
        if(!is_file(APP_PATH."common/model/".ucfirst($name).".php") && config("app_debug"))
        {
            $str = "<?php \n namespace app\common\model; \n use think\Model; \n use think\Cache;  \n use traits\model\SoftDelete;  \n class ".$name." extends  Model \n {";
            if($softdeletet)
            {
                $str .= "use SoftDelete; \n";
                $str .= "protected $deleteTime = '".$softdeletet."' \n";
            }        
            $str .= "}";
            file_put_contents(APP_PATH."common/model/".ucfirst($name).".php",$str);
        }
        
        return Loader::model($name, $layer, $appendSuffix);
    }
评论( 相关
后面还有条评论,点击查看>>