CC,
I’ve extended DataMapper without issue. You should echo $this->model right before the error, to see which model exactly is causing the error (unless you already know).
What is the exact version of PHP are you using?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 05, 2008 12:32pm
Subscribe [115]#361 / Dec 12, 2008 3:59pm
CC,
I’ve extended DataMapper without issue. You should echo $this->model right before the error, to see which model exactly is causing the error (unless you already know).
What is the exact version of PHP are you using?
#362 / Dec 12, 2008 4:49pm
Hrm, so i’ve got the same setup that was working before. None of the autoloads or config stuff has changed. It now appears that it’s not specific to extends, but merely when i instantiate any child of datamapper or even DM itself.
I created a blank model and test controller for simplicity. I do have the model echoed, which DOES work, but calling the parent constructor triggers an error.
// Model
class Name extends DataMapper {
var $model = 'name';
var $table = 'names';
function Name()
{
echo $this->model;
parent::DataMapper(); // Error Triggered
}
}
// Controller
class Test extends Controller {
function Test() {
parent::Controller();
}
function index() {
$n = new Name();
}
}Also, as mentioned above, it brings up the error even if i just simply instantiate DM
// Test Controller
function index() {
$dm = new DataMapper();
}
// Triggers Error
// Message: array_keys() [function.array-keys]: The first argument should be an array
// Filename: libraries/datamapper.php
// Line Number: 79
The only thing that works so far is if i refer to the global instantiated class
// Test Controller
function index() {
echo $this->datamapper->model;
}Heh, but that’s not too useful i suppose. I’m racking my brain on this, and i KNOW its gotta be something ridiculously small i’ve overlooked. Google searching is being no help either..
I am using MAMP with PHP Version 5.2.3
thx,
CC
#363 / Dec 12, 2008 5:04pm
Try looking into accessing DataMapper::$config - seeing if it exists in different contexts (not from a model, just from a controller). Try using print_r(DataMapper::$config) to see exactly what the $config data is.
I’m using 5.2.6, but I can’t find any info in the PHP docs that says they changed something regarding static vars between the versions.
Have you tried re-downloading DM 1.6.0 and overwriting your version? Just in case it got corrupted somehow?
I am now wondering if something is happening to the actual config data. You are using CI 1.7, correct? In other words, it works the first time because DataMapper::$config is hard-coded to be an empty array. Then DM tries to replace it with the content of Config->item(‘datamapper’), and that is returning NULL or a string for some reason.
Are you autoloading the DataMapper config? That could be breaking it. Definitely don’t do that.
#364 / Dec 12, 2008 5:12pm
Okay, hrm, one more test.
So i simply added a var_dump in the DataMapper Constructor :
function DataMapper()
{
$this->_assign_libraries();
var_dump(DataMapper::$config);
...
}So, the first time it’s loaded (through the autoloading of DM), it spits out
array(0) { }
which looks fine, but with the instatiation of it, the second time the constructor is called, the var_dump prints
bool(false)
so, it looks like it’s somehow unable to retrieve the static array after the class instantiates once.. I don’t have a lot of experience with static variables, but i’m sure i’ve run them in the same environment. I’m going to do some more testing on this, but any idears would help a ton.
thanks again,
CC
UPDATE: SOLVED - see below
#365 / Dec 12, 2008 5:43pm
@OverZealous
Alright cool, i posted the last message just as you did i guess. That did it. I did have the cofig autoloaded, and it was screwing it up. I must have missed that detail at some point. Anyway, so that’s resolved now, Thank you very much.
One more new prob that’s popping up, and you also may be able to help with this because i believe you use a general Datamapper extension. I have one also, DataMapperObject, which extends DM and then my models extend that. But now i get this notice :
A Database Error Occurred
Error Number: 1146
Table 'dinofuelalte.ncore_datamapperobjects' doesn't exist
SELECT * FROM `ncore_datamapperobjects` LIMIT 1Even though my models explicitly state their table, the Datamapperobject doesn’t have one (like datamapper itself doesn’t)
have you had a similar prob with children of DM?
CC
UPDATE: Okay, nvm. I added the code
if($this->model == 'datamapperobject')
{
return;
}and it loads it fine.. still getting used to the new version i guess. 😛
#366 / Dec 12, 2008 9:50pm
Actually, I don’t think the config issue is mentioned anywhere, maybe something for stensi to add to the docs.
What happens is the datamapper defaults are being loaded into the global config, and config is then storing that it has already been loaded. But DM needs the config info to be loaded into it’s own “datamapper” array (not mixed in), so it loads it using the optional arguments. However, config, sees that it already has loaded it, skips the load, and then config->item(‘datamapper’) is never set.
That was a tricky one, at any rate.
As for your other problem, how are you storing your DataMapperObject? As a Model? As a Library? I keep my extension class in the models folder. DM usually warns that the table doesn’t exist, but I’ve never seen an error otherwise.
#367 / Dec 13, 2008 6:26pm
Possible bug, or I don’t understand what’s going on here.
This code:
$user=new User();
$user->select('id', 'email')->get_where(array('username' => $username), 1);
$user->activation_code->get();Causes this error:
A Database Error Occurred
Error Number: 1054
Unknown column 'activation_codes.*' in 'field list'
SELECT `activation_codes`.`*` FROM (`activation_codes`) LEFT JOIN `activation_codes_users` ON `activation_codes`.`id` = `activation_codes_users`.`activation_code_id` LEFT JOIN `users` ON `users`.`id` = `activation_codes_users`.`user_id` WHERE `users`.`id` = 40However changing the code to this:
$user=new User();
$user->select('id', 'email')->get_where(array('username' => $username), 1);
$user->activation_code->select('activation_code')->get(); //added select statementWorks fine. Is this a bug or am I doing something wrong?
#368 / Dec 13, 2008 7:03pm
It is a bug, but it’s in CodeIgniter 1.7.0.
The the Installation Instructions in the DataMapper User Guide says before installing DataMapper you need to install the latest SVN version of the MySQL Driver. The instructions on how to do that is in the Troubleshooting section.
This will prevent the…
A Database Error Occurred
Error Number: 1054
Unknown column 'table.*' in 'field list'...type of error.
#369 / Dec 14, 2008 5:19am
Oops! Didn’t know that was in the manual.
Anyways, I just realized that DataMapper has a big flaw - you can’t use select() and then save() on the same object - since only some of the fields are loaded, DM thinks they are missing and any fields set as required fail validation.
#370 / Dec 14, 2008 6:23am
That’s true but it comes with the territory when using database validation. If you’ve set something to be required, then you’ll have to select it.
#371 / Dec 14, 2008 3:11pm
Eww having to select whole rows just to modify one value is really dirty and inefficient. I might just have to program in a hack. I’m thinking of adding a boolean to the Save() function that will only validate values that are present. Or maybe I could make it so it looks at what values where selected() and then only validates those.
#372 / Dec 15, 2008 3:22am
You may want to change this:
function _get_by($field, $value = array())
{
if (isset($value[0]))
{
$this->where($field, $value[0]);
}
return $this->get();
}To this:
function _get_by($field, $value = array())
{
$this->where($field, $value[0]);
return $this->get();
}The reason being, is because if I do $user->get_by_username($string_thats_empty), instead of returning no results, it defaults to returning ALL users. I don’t see why this functionality would ever be needed.
#373 / Dec 16, 2008 5:34am
hi,everybody.
How can I get a data row with array type not object type?
from
$o = new Object();
$o->get();
echo $o->title;to
$o = new Object();
$row = $o->get();
echo $row['title'];has any params can to use?
thank your reply
#374 / Dec 16, 2008 7:32am
I’ll be adding in an as_array() method soon that transforms not just the current object record but its all list as well, into an array.
For now, you can transform just the current object record via the _to_array():
$o = new Object();
$o->get();
$row = $o->_to_array();
echo $row['title'];#375 / Dec 16, 2008 7:56pm
Ive got a question on how I would link these together
Im having an issue with the fact that i need a contact_id and a updated_by id, both go to the users table… How do i setup a relationship for this???
Heres the layout
CREATE TABLE IF NOT EXISTS `brainstorms` (
`id` int(10) unsigned NOT NULL auto_increment,
`priority` int(11) default NULL COMMENT 'left as signed in case of negative priorities',
`status` tinyint(1) unsigned NOT NULL default '1' COMMENT 'bit wise field see documentation',
`short_desc` varchar(255) NOT NULL COMMENT 'AKA title',
`long_desc` text,
`origin_date` int(10) unsigned default NULL COMMENT 'unixtime where NULL = unknown',
`est_count_total` int(10) unsigned default '0',
`est_count_manual` int(10) unsigned default '0',
`updated_on` int(10) unsigned NOT NULL COMMENT 'DataMapper automated timestamp in unixtime',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_idx_brainstorm_short_desc` (`short_desc`),
KEY `idx_brainstorm_status` (`status`),
KEY `idx_brainstorm_priority` (`priority`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `data_sources` (
`id` int(10) unsigned NOT NULL auto_increment,
`short_desc` varchar(255) character set utf8 NOT NULL,
`long_desc` text character set utf8,
`status` tinyint(1) unsigned NOT NULL default '1',
`updated_on` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_idx_data_source_short_desc` (`short_desc`),
KEY `idx_data_source_status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `issue_types` (
`id` int(10) unsigned NOT NULL auto_increment,
`short_desc` varchar(255) NOT NULL,
`long_desc` text,
`status` tinyint(1) unsigned NOT NULL default '1' COMMENT 'bit wise field',
`updated_on` int(10) unsigned NOT NULL COMMENT 'DataMapper automated timestamp in unixtime',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_idx_issue_type_short_desc` (`short_desc`),
KEY `idx_issue_type_status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `join_brainstorms_data_sources` (
`id` int(10) unsigned NOT NULL auto_increment,
`brainstorm_id` int(10) unsigned NOT NULL,
`data_source_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
CREATE TABLE IF NOT EXISTS `join_brainstorms_issue_types` (
`id` int(10) unsigned NOT NULL auto_increment,
`brainstorm_id` int(10) unsigned NOT NULL,
`issue_type_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `join_brainstorms_user` (
`id` int(10) unsigned NOT NULL auto_increment,
`brainstorm_updatedpid_id` int(10) unsigned NOT NULL,
`brainstorm_contactpid_id` int(10) unsigned NOT NULL,
`brainstorm_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `join_user_profiles_users` (
`id` int(10) unsigned NOT NULL auto_increment,
`user_profile_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL auto_increment,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`salt` varchar(32) NOT NULL,
`email` varchar(255) NOT NULL,
`status` tinyint(1) unsigned NOT NULL default '1' COMMENT 'bit wise field see documentation',
`updated_on` int(10) unsigned NOT NULL COMMENT 'DataMapper automated timestamp in unixtime',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_idx_username` (`username`),
UNIQUE KEY `uniq_idx_email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
CREATE TABLE IF NOT EXISTS `user_profiles` (
`id` int(10) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`is_primary` tinyint(1) unsigned NOT NULL default '0' COMMENT 'Boolean that defaults to false',
`active_start_date` int(10) unsigned NOT NULL COMMENT 'unixtime',
`active_end_date` int(10) unsigned default NULL COMMENT 'unixtime',
`status` tinyint(1) unsigned NOT NULL default '1' COMMENT 'bit wise field see documentation',
`updated_on` int(10) unsigned NOT NULL COMMENT 'DataMapper automated timestamp in unixtime',
PRIMARY KEY (`id`),
KEY `idx_user_profiles_title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;