Reputation: 23297
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?
Upvotes: 0
Views: 1081
Reputation: 20753
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.
Upvotes: 1