Search code examples
phpphpactiverecord

php activer record Uncaught ActiveRecord\ActiveRecordException Class not found


I have a file index.php and in the same level I have a folder called models where I have my user model User.php

I am trying to user php active-record library, so I downloaded the library and put it inside a folder called core, the structure looks like this:

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

My User model is pretty simple :

<?php

    class User extends ActiveRecord\Model{


        public function __construct(){

        }


    }

and my index.php file looks like this :

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' => '[email protected]', 'password' => 'blahblah'));

die();

When I visit index.php I get the following error :

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

I am not sure why this happens ? I tested the connextion (using pdo) to my database and everything working ! any help ?


Solution

  • You included your core phpmyadmin file, but not your user file. The class is therefore not loaded, as the error says.