0

I have installed Wanwizard's Datamapper (http://datamapper.wanwizard.eu) in an empty codeigniter setup.

I have no problem using datamapper in my controllers, but when I try to call datamapper objects in my libraries.

I get the error: Fatal error: Class 'User' not found.

This is my code for my library:

class Auth {

    protected $ci;

    public function __construct()
    {
        $this->ci =& get_instance();
        $this->ci->load->library('datamapper');
    }

    public function signup( $username, $email, $password )
    {   
        $user = new User();
    }
}

Does anyone know the correct way to call these datamapper objects within libraries?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Is `User` a custom class object? If it does, you need to make the `include`. If `User` is in a namespace, you should make `new models\User()`. – manix Oct 31 '12 at 02:21
  • strange, I have no problems instantiating DM models in my libraries. You sure you have a `models/user.php` file? – Jordan Arsenault Oct 31 '12 at 05:04
  • `modes_or_whatever\User` is an example. Where is located User class? – manix Oct 31 '12 at 16:21
  • Ideally you should autoload Datamapper, but this should work fine to. Did you install the bootstrap as well? If you get this error either a file called user.php can't be found in the defined datamapper paths, or the file doesn't contain a class called User. – WanWizard Oct 31 '12 at 16:58

1 Answers1

2

You probably have resolved this already. To folks of the future visiting this:

The issue, as WanWizard points out, is either:

  1. You aren't autoloading datamapper in application/config/autoload.php: $autoload['libraries'] = array('database', 'datamapper');

  2. The application/models folder does not contain a User.php file.

  3. The User.php file does not contain a class User extends Datamapper{}.

Also -- Linux is a case sensitive operating system, be careful to follow the cases used in the Datamapper and CodeIgniter documentation when naming your files.

Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96