CodeIgniter Forums
DataMapper ORM v1.8.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper ORM v1.8.0 (/showthread.php?tid=37531)



DataMapper ORM v1.8.0 - El Forum - 05-09-2011

[eluser]WanWizard[/eluser]
The reason static calls are used is that you can do that without actually creating an object instance. The static class also provide the instances (that are created when you instantiate a model) with setup and configuration information.

Removing it would lead to complex code and 'hacks' to store the information somewhere (for example a separate class loaded as a CI singleton).

In your case I would have copied the entire application folder to a second CI installation, copied the latest Datamapper files in, changed the database config to a test db, and started testing. A lot easier then modifying code...


DataMapper ORM v1.8.0 - El Forum - 05-09-2011

[eluser]AMR[/eluser]
@WanWizard Thanks!

Ok I understand what you mean now. No worries

Thanks


DataMapper ORM v1.8.0 - El Forum - 05-10-2011

[eluser]cube1893[/eluser]
Hi,

I have a question concerning self-relationships, like friendships between users.

I've setup the table as it is described here: http://datamapper.wanwizard.eu/pages/advancedrelations.html.

Now, I want to have additional information in that table, like "date_created". What's the best solution to achieve this?

Thank you!

EDIT: I just realized that I could simply use a join field, sorry, it came to my mind when I posted the question :-)


DataMapper ORM v1.8.0 - El Forum - 05-10-2011

[eluser]Andy78[/eluser]
Is DataMapper v1.8.0 compatible with Modular Extensions - HMVC version 5.3? I am currently using Modular Extensions - HMVC version 5.3 and the latest version of CI and looking to at an ORM. Anything specific I need to do to get these working togther?


DataMapper ORM v1.8.0 - El Forum - 05-10-2011

[eluser]GeXus[/eluser]
I've just setup v1.8.0 in a new project using CI 2.0.2 and I keep getting a blank page when trying to test.

I've setup a 'users' table and have a User model and a Users controller.

I'm loading the datamapper and setup the configs accordingly.

My User model has this:

Code:
<?php

class User extends DataMapper {

    var $validation = array(
        array(
            'field' => 'name',
            'label' => 'Name',
            'rules' => array('required', 'trim')
        )
    );

Controller has:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

    public function index()
    {
        
    }
    
    public function add(){
        
        $this->output->enable_profiler(TRUE);
        
        $o = new User();
        $o->name = 'user name';
        if($o->save()){
            echo 'saved';    
        }else{
            foreach ($o->error->all as $error)
            {
                echo $error;
            }
        }        
        

        
    }
}

Any ideas what could be wrong? I have level 4 logging and it doesn't show any errors, but the page is blank when I add in the call to new User()


DataMapper ORM v1.8.0 - El Forum - 05-10-2011

[eluser]GeXus[/eluser]
I get the error:

Fatal error: Call to undefined function User() in /home/domain/public_html/application/controllers/admin/users.php on line 14


DataMapper ORM v1.8.0 - El Forum - 05-11-2011

[eluser]cube1893[/eluser]
I can't see a constructor in your controller.
Try to add these lines at the constructor class:

Code:
function __construct()
{
   parent::__construct();
}

EDIT:
I think the real problem is a naming problem: Both Model and Controller have the same name "User". Change one of them and it might work.


DataMapper ORM v1.8.0 - El Forum - 05-11-2011

[eluser]Daniel H[/eluser]
I have just updated CI and Datamapper to the latest versions (1.8.0 datamapper, and the latest reactor build of CI) and I get this error when performing a simple save that used to work okay:

Code:
Fatal error: Cannot access protected property CI_Loader::$_ci_classes in /...path to.../application/libraries/Datamapper.php on line 1081

This is that line:

Code:
unset($CI->load->_ci_classes['form_validation']);

I can't spot what the problem is - any ideas?


DataMapper ORM v1.8.0 - El Forum - 05-11-2011

[eluser]GeXus[/eluser]
[quote author="cube1893" date="1305111923"]I can't see a constructor in your controller.
Try to add these lines at the constructor class:

Code:
function __construct()
{
   parent::__construct();
}

EDIT:
I think the real problem is a naming problem: Both Model and Controller have the same name "User". Change one of them and it might work.[/quote]

The model is named 'User' and the controller is 'Users' (plural).

I've added the construct function, but I still get the same error:
Fatal error: Call to undefined function User()

It seems like it must be something with the Autoload? There is no User() function, except for what would be mapped to an object from the model


DataMapper ORM v1.8.0 - El Forum - 05-11-2011

[eluser]gh0st[/eluser]
I'm having a problem with Update; it never seems to run a validation; even though I know the data I am entering into the field is invalid.

For example.

I have a basic model;

Code:
class Worker extends DataMapper
{
    var $table = 'tbl_worker';
    
    var $error_prefix = '<div class="error">';
    var $error_suffix = '</div>';

    var $validation = array(
        array(
        'field'    => 'fname',
        'label' => 'First name',
        'rules'    => array ('required', 'trim', 'min_length' => 2)
        )
    );
// constructor etc goes here
}

And in my code I use the following.

In the following example I use an array for updates, and for an insert I build up an associate array of all the stuff I want to save.

I've verified both the keys/contents of the array, and have even done a var_dump to ensure that the fields have a value, etc.

Code:
// ---
// Save

$success = $w->where('id =', $final['id'])->update(
    $final
);

/*
foreach($final as $key => $value):
    //print $key . ' --&gt; '. $value . '<br>';
    $w->$key = mysql_real_escape_string(trim($value));
endforeach;

//$w->id = $

$success = $w->save();
*/

// did validation fail?
if ( $w->valid == false)
{
    print 'Errors';
    foreach ($w->error->all as $e)
    {
        echo $e . "<br />";
    }
} else {

    print 'Validation was ok';
    
    
    pre_print_r($w);
}

pre_print_r($final);

die();

Basically, if you enter 0 characters into the fname field it should be validating and throwing up an error because in my validation rules I made fname a required field.

In my var_dump of final I got:

Code:
["fname"]=> string(0) ""

You will notice in my second block of code. If I uncomment this, and do a $w->save instead of a `update` it still causes the same problem.

However, I have noticed that if I do a new entry and purposely do not enter a fname it will throw up an error.

I outputted the $w using a pre_print_r and tried to find valid and it says:

Code:
[error] => DM_Error_Object Object
        (
            [all] => Array
                (
                )

            [string] =>
        )

...

[valid] =>

Summary.

1. If I do an insert and leave fname blank an error is thrown. Validation is working.

2. If I do an insert, and then edit the record and leave the fname blank, it does not validate and saves. Validation is not working?


I don't understand what I'm doing wrong.

Thanks.