tp3.2 新建模型的问题

user模块下RegistorController.class.php 和RegistorModel.class.php

RegistorController.class.php 代码

namespace User\Controller;
use Think\Controller;
use User\Model\RegistorModel;

class RegistorController extends Controller
{

    public function test(){
        new RegistorModel();
//        D('Registor');
    }
}

RegistorModel.class.php

namespace User\Model;
use Think\Model;

class RegistorModel extends Model
{

}

访问地址test()方法,提示无法加载数据库驱动: ThinkDbDriver\
就这么几行代码,整整一上午,tp和核心代码我又重下了一遍.能排除的我都排除了,郁闷死了
tp的详细报错信息

无法加载数据库驱动: Think\Db\Driver\
错误位置
FILE: D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\Db.class.php  LINE: 42
TRACE
#0 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\Db.class.php(42): E('\xE6\x97\xA0\xE6\xB3\x95\xE5\x8A\xA0\xE8\xBD\xBD\xE6\x95\xB0...')
#1 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\Model.class.php(1443): Think\Db::getInstance('')
#2 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\Model.class.php(97): Think\Model->db(0, '', true)
#3 D:\www\oschina\Addons_Project\Addons\Application\User\Controller\RegistorController.class.php(16): Think\Model->__construct()
#4 [internal function]: User\Controller\RegistorController->test()
#5 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\App.class.php(173): ReflectionMethod->invoke(Object(User\Controller\RegistorController))
#6 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\App.class.php(110): Think\App::invokeAction(Object(User\Controller\RegistorController), 'test')
#7 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\App.class.php(204): Think\App::exec()
#8 D:\www\oschina\Addons_Project\Common\ThinkPHP\Library\Think\Think.class.php(120): Think\App::run()
#9 D:\www\oschina\Addons_Project\Common\ThinkPHP\ThinkPHP.php(97): Think\Think::start()
#10 D:\www\oschina\Addons_Project\Addons\index.php(28): require('D:\\www\\oschina\\...')
#11 {main}
阅读 3.7k
4 个回答

$registor= D('Registor');
conf目录下的config.php,你应该在Common目录下的conf目录下的config.php进行数据库的配置,不是在Home目录下的conf目录下的config.php.

看看配置文件DB_TYPE这里应该是mysql

查看数据库配置是否正确,实例化自定义model用D("Registor")

多年老司机经验,一楼为正解,其他得非也。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题