php activer record未找到ActiveRecord \ ActiveRecordException类未找到

时间:2016-12-10 14:06:23

标签: php phpactiverecord

我有一个文件index.php,在同一级别我有一个名为models的文件夹,我有我的用户模型User.php

我正在尝试使用php active-record库,所以我下载了库并将其放在名为core的文件夹中,结构如下所示:

|
|---> index.php
|---> models/User.php
|---> core/php-activerecord

我的用户模型非常简单:

<?php

    class User extends ActiveRecord\Model{


        public function __construct(){

        }


    }

我的index.php文件如下所示:

require_once 'core/php-activerecord/ActiveRecord.php';

 ActiveRecord\Config::initialize(function($cfg)
 {
     $cfg->set_model_directory('models');
     $cfg->set_connections(array(
         'development' => 'mysql://root:@localhost/ar'));
 });


 $user = User::create(array('name' => 'test', 'email' => 'test@test.com', 'password' => 'blahblah'));

die();

当我访问index.php时出现以下错误:

Fatal error: Uncaught ActiveRecord\ActiveRecordException: Class not 

found: User in /home/mody/php_projects/membership/core/php-activerecord

/lib/Reflections.php:66 Stack trace: #0 /home/mody/php_projects/membership

/core/php-activerecord/lib/Validations.php(95): 

ActiveRecord\Reflections->get('User') #1 /home/mody/php_projects/membership

/core/php-activerecord/lib/Model.php(1044): 

ActiveRecord\Validations->__construct(Object(User)) #2 /home/mody/php_projects

/membership/core/php-activerecord/lib/Model.php(791): 

ActiveRecord\Model->_validate() #3 /home/mody/php_projects/membership

/core/php-activerecord/lib/Model.php(777): ActiveRecord\Model->insert(true) 

#4 /home/mody/php_projects/membership/core/php-activerecord

/lib/Model.php(758): ActiveRecord\Model->save(true) #5 /home/mody/php_projects

/membership/index.php(25): ActiveRecord\Model::create(Array) #6 {main} thrown 

in /home/mody/php_projects/membership/core/php-activerecord

/lib/Reflections.php on line 66

我不确定为什么会这样?我测试了连接(使用pdo)到我的数据库,一切正常!有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您包含了核心phpmyadmin文件,但不包括您的用户文件。因此错误说明没有加载该类。