Welcome Guest, Not a member yet? Register   Sign In
DataMapper 1.6.0

[eluser]OverZealous[/eluser]
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?

[eluser]ntheorist[/eluser]
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.
Code:
// 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
Code:
// 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
Code:
// 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

[eluser]OverZealous[/eluser]
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.

[eluser]ntheorist[/eluser]
Okay, hrm, one more test.

So i simply added a var_dump in the DataMapper Constructor :
Code:
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

[eluser]ntheorist[/eluser]
@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 :
Code:
A Database Error Occurred

Error Number: 1146

Table 'dinofuelalte.ncore_datamapperobjects' doesn't exist

SELECT * FROM `ncore_datamapperobjects` LIMIT 1
Even 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
Code:
if($this->model == 'datamapperobject')
{
    return;
}
and it loads it fine.. still getting used to the new version i guess. Tongue

[eluser]OverZealous[/eluser]
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.

[eluser]ryeguy[/eluser]
Possible bug, or I don't understand what's going on here.

This code:
Code:
$user=new User();
$user->select('id', 'email')->get_where(array('username' => $username), 1);
$user->activation_code->get();

Causes this error:
Code:
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` = 40

However changing the code to this:
Code:
$user=new User();
$user->select('id', 'email')->get_where(array('username' => $username), 1);
$user->activation_code->select('activation_code')->get(); //added select statement

Works fine. Is this a bug or am I doing something wrong?

[eluser]stensi[/eluser]
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...

Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'table.*' in 'field list'

...type of error.

[eluser]ryeguy[/eluser]
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.

[eluser]stensi[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB