CodeIgniter Forums
DataMapper 1.6.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 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]hugle[/eluser]
Thank you OverZealous.com very much!
It now works as used to work always Smile

Good luck using DataMapper!Smile


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]hugle[/eluser]
Yesterday I saw, that neither header ('Location: /'); nor redirect () do not work.

Today I have reproduced it, and spotted, that if I put datamaper, in autoload.php like:
Code:
$autoload['libraries'] = array('datamapper');

and make simple Test controller:
Code:
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }

    function index()
    {        

    }
}

When I navigate to the page, and make View Source, the content is " " (one whitespace)

When I remove datamapper from autoload, refresh the page, it loads without a " ".

Anyone spotted similar issues ? or even knwo a workaround ?

Thanks !


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]OverZealous[/eluser]
Are you adding database to your autoload first? You need database in there as well.

Please take a minute to read over the DataMapper User's Guide. It explains a lot of this, and other problems you have been having, and it isn't very long. DM is slightly different than using straight CodeIgniter in some respects.

Also, make sure you don't have any files with leading spaces before the <?php. This is a well known problem with PHP. It's even more of an issue if you have files being saved as UTF-8 with a leading BOM (byte-order mark). Search the web for "PHP BOM" to see how to remove it.


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]hugle[/eluser]
Yes OverZealous, I have tried adding database, like
Code:
$autoload['libraries'] = array('database', 'datamapper');
also.. the problem still exists. If I remove the datamapper from autoload, the redirects and header ('Location: /'); do start to work.
I also tried to load even more libraries, redirects work until I add the 'datamapper' library..

I went through the documentation but somehow I didn't find anything similar that could lead to such a behavior.

It is strange, because when I remove datamapped from autoloader, it starts to work, so I think it is not the
PHP BOM issue, or white spaces before the <?php.

And yes, I was using UTF-8, also tried to save file as windows-1257 - same result.

I think maybe there could be a white space somewhere in DM library?


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]OverZealous[/eluser]
I know that the DM I am using, the latest one, has no whitespace issue. The whitespace/BOM is probably occuring within one of your models, or within a language file, or something similar.

DM loads all of the models within your application/models directory on init. Therefore, if any php file in this directory has this problem, it will show up.


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]hugle[/eluser]
OverZealous , thans for your thoughts.
Well, i went a bit further now.

So I started checking the libraries and the models directories. What I came up with,
is that problem lays somethere in MY_Form_validation.php.

[update]
after looking into it, I've spoted some whitespace. thanks for your time, I really appreaciate it, OverZealous.

Now i understend CI and DM even more.
cheers,
Jaroslav


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]OverZealous[/eluser]
Good Stuff! :-)

I can't stand those time-consuming, little tiny bugs. I think I spend twice as long fixing bugs that are bizarre and tiny than I do the severe ones!


DataMapper 1.6.0 - El Forum - 12-08-2008

[eluser]hugle[/eluser]
Strange this bug didn't came out earlier - bastardSmile but thanks again, really!

I must agree with you OverZealous, those little bugs consume too much time sometimes...
sometimes you need to write a script which takes <10 mins, instead of this it eats you 2 hours or so Smile))


DataMapper 1.6.0 - El Forum - 12-09-2008

[eluser]hugle[/eluser]
Hello Smile
It is me again, hope you did miss me Wink)))

I'm playing with Relationships,
my structure is as follows:

forum has many topic
topic has many post

here is an example I'm working on
Code:
$f = new Forum();
        $f->get();

        foreach ($f->all as $forum)
        {
            //part1
            $f2 = new Forum();
            $f2->get_by_id($forum->id);
            $topic_count = $f2->topic->count(); // save topic count for later use

            //part2
            $t2 = new Topic();
            //...
            
            $data['forum'][] = array(id => $forum->id, title => $forum->title, topic_count => $topic_count, post_count => $post_count);
        }

Part1 works well,
but I'm stuck at part2. Can't figure out how I can make relations between
forum<>topic<>post and count it...

Maybe some of you have some examples or thoughts on this approach?

Thank you Smile


DataMapper 1.6.0 - El Forum - 12-09-2008

[eluser]stensi[/eluser]
Version 1.6.0 has been released!

View the Change Log to see what's changed.

In short, there are now advanced queries. Let's go through an example to see the benefits of these.

Let's say we have a User model and a Group model. A group can have many users but a user can only have one group. Here's how you would look up all users belonging to the Moderator group without the advanced query:

Code:
// Create user object
$u = new User();

// Get all users
$u->get();

// Loop through all users
foreach ($u->all as $user)
{
    // Get the current user's group
    $user->group->get();
    
    // Check if user is related to the Moderator group
    if ($user->group->name == 'Moderator')
    {
        // ...
    }
}

Here's how you would do the above, but using an advanced query:

Code:
// Create user object
$u = new User();

// Get users that are related to the Moderator group
$u->where_related_group('name', 'Moderator')->get();

// ...

As you can see, it's a big time saver but not just in the amount of code you write, but also in the number of database queries and overall processing time. There are alternate usage formats as well. Here's one of the variants of the above:

Code:
// Create and get Moderator group
$g = new Group();
$g->get_by_name('Moderator');

// Create user object
$u = new User();

// Get users that are related to the Moderator group
$u->where_related($g)->get();

Or you could use the advanced Get By:

Code:
$u->get_by_related($g);

// or

$u->get_by_related_group('name', 'Moderator');

// etc.

Enjoy :-)