0
votes

I'm trying to use datamapper in CodeIgniter. I've already set it up using the installation instructions

<?php
class Users extends DataMapper{

function Users(){
    parent::DataMapper();
}

function create($username, $hashed_password, $salt, $department_id, $role_id){
    $user = new User();
    $user->username = $username;
    $user->hashed_password = $hashed_password;
    $user->salt = $salt;
    $user->department_id = $department_id;
    $user->role_id = $role_id;

    $user->save();
}

I've already setup the database information on database.php I've also autoloaded datamapper and database library. Here's the error that I'm getting:

Error Number: 1146

Table 'rpt.datamappers' doesn't exist

DESCRIBE `DataMappers`

Filename: D:\web_files\tester\php\ci_tester\system\database\DB_driver.php

Line Number: 330

What did I miss?

1
Hi, did you use the latest CI version? - Ivan
yes and I don't know how to update the codes in the examples as it wasn't implemented using the latest CI version - Wern Ancheta
You are using an old version of datamapper. The development is now being done by Wanwizard. You should use his version, which you can find at his website. - Zombaya
As far as i tried. it is working correctly and no error. i'm using the latest datamapper and latest CI. let me know if you need the file sample. - Ivan
@Ivan: yes I guess I need a sample as I've already tried installing the latest datamapper but I'm still getting this error: Call to undefined method CI_DB_mysqli_driver::dm_call_method() - Wern Ancheta

1 Answers

1
votes

I think you have the wrong class name somewhere in the example, your class called "Users" but in the create method you call "new User".

The error message "Table 'rpt.datamappers' doesn't exist" actually comes from your database. It looks like the automagick that generates table names took the wrong class name (DataMapper) instead of "User(s?)", try setting the table name explicitly to your DataMapper descendant classes like this, to confirm:

class Users extends DataMapper{
    public $table = 'users';
    // ...
}

also, if you just want to delegate to the parent constructor don't override it with your own, especially if you don't preserve signature of the method.