Welcome Guest, Not a member yet? Register   Sign In
upgrade from 1.4.x to 2.1.2 datamapper installation.
#1

[eluser]Grego606[/eluser]
I thought I had followed the instructions closely for installing datamaper:

http://datamapper.wanwizard.eu/pages/installation.html

But I get this error:

Fatal error: Class 'bands' not found in /home/opendoor/public_html/classicgaragerock.com/application/libraries/datamapper.php on line 1072

Code:
line 1072  $this->{$name} = new $class();

// bands is one of the tables that gets converted in datamapper.
#2

[eluser]WanWizard[/eluser]
Datamapper doesn't do anything with tables, it deals with models.

So that should autoload /application/models/bands.php, which should contain a class called "Bands" which must extend Datamapper.
#3

[eluser]Grego606[/eluser]
[quote author="WanWizard" date="1349851023"]Datamapper doesn't do anything with tables, it deals with models.

So that should autoload /application/models/bands.php, which should contain a class called "Bands" which must extend Datamapper.[/quote]

You are quite correct. Forgive my inaccuracy.

Is this how my models should look?

Code:
<?php

class Band extends DataMapper {

var $has_many = array('song' => 'songs', 'file' => 'files');
var $has_one  = array('label' => 'labels');

    function Band($condition = array())
    {
        parent::DataMapper($condition);
    }
}
#4

[eluser]WanWizard[/eluser]
No.

As shown here and on the next page, you would normally use

Code:
var $has_many = array('song', 'file');
var $has_one  = array('label');
assuming your models are called 'song', 'file' and 'label'.

If your models are defined non-standard, or you want the relation name to be different from the model name, you need the advanced relationship notation, as documented here.
#5

[eluser]WanWizard[/eluser]
Also,

What is the intention of this method:
Code:
function Band($condition = array())
{
    parent::DataMapper($condition);
}

If it's meant to be a constructor, use __construct() instead. You can't call parent:Big Grinatamapper, you have to call parent::__construct(), as documented here.

And the constructor parameter is a numeric id, not an array...
#6

[eluser]Grego606[/eluser]
Thank you that helps a lot.

My new error code is:


Fatal error: Class 'labels' not found in /home/opendoor/public_html/classicgaragerock.com/application/libraries/datamapper.php on line 1072

The only place I can find a reference to "labels" is in a file called "common_model.php" This file joins various tables.

Is it coded correctly for Datamapper?

[code

class Common_model extends DataMapper {
.
// let me know if you need to see this code
.

//------- CUSTOM --------//

function get_bands($iLimit = null, $iOffset = 0)
{
$oData = new stdClass;

$oData->total = $this->db->count_all_results('bands');

$this->db->select('bands.*, labels.name as label');
$this->db->from('bands');
$this->db->join('bands_labels', 'bands.id = bands_labels.band_id', 'left');
$this->db->join('labels', 'labels.id = bands_labels.label_id', 'left');
if (! is_null($iLimit)) $this->db->limit($iLimit, $iOffset);
$this->db->order_by('labels.name asc, bands.sort asc');

if ($query = $this->db->get())
{
$oData->result = $query->result();
$this->db->flush_cache();
return $oData;
}

return false;
}

function get_songs($iLimit = null, $iOffset = 0)
{
$oData = new stdClass;

$oData->total = $this->db->count_all_results('songs');

$this->db->select('songs.*, bands.name as band, labels.name as label');
$this->db->from('songs');
$this->db->join('bands_songs', 'songs.id = bands_songs.song_id', 'left');
$this->db->join('bands', 'bands.id = bands_songs.band_id', 'left');
$this->db->join('labels_songs', 'songs.id = labels_songs.song_id', 'left');
$this->db->join('labels', 'labels.id = labels_songs.label_id', 'left');
if (! is_null($iLimit)) $this->db->limit($iLimit, $iOffset);
$this->db->order_by('labels.name asc, bands.sort asc, songs.sort asc');

if ($query = $this->db->get())
{
$oData->result = $query->result();
$this->db->flush_cache();
return $oData;
}

return false;
}
}[/code]

Thank you so much for looking at this.
#7

[eluser]WanWizard[/eluser]
wasn't labels one of your relations?

And why do you have a datamapper model that does db calls? If your model doesn't implement Datamapper, you better extend CI_Model instead, it will save you some memory and CPU.
#8

[eluser]Grego606[/eluser]
I inherited this site. It was working fine till my isp decided to update php to the latest version, and my side broke.

I am attempting to upgrade CI to the latest version. I saw DM files in my forensic reconstruction of the site.

There were calls for it in the legacy site...
#9

[eluser]WanWizard[/eluser]
If this was a CI 1.4 site, chances are it is even using Stensi's Datamapper. Which has been dead for several years, and mine isn't really compatible anymore (it's around since early 2009).
#10

[eluser]Grego606[/eluser]
What do you recommend?





Theme © iAndrew 2016 - Forum software by © MyBB