Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)
#31

[eluser]BrianDHall[/eluser]
Pardon me if this is a silly question, but consider this:

$user->usergroup->get();

So you get the usergroup that the user belongs to - simple. But where the hell is the usergroup object?

If I do:

$usergroup = $user->usergroup;

...that works, and $usergroup is now my usergroup object. When I use my debugger to look into the $user object, there is no sign of usergroup anywhere in it, nor in any other variable I can seem to locate.

If I want to peek into the structure of such a related object, do I need to assign it to a variable before I'll be able to see it, or am I just missing where it might be hiding?

EDIT: The point of this is mainly for debugging purposes, and technically I'm trying to hand off one of my Datamapper objects in a way friendly to the CI Template parser, since it isn't capable of understanding object properties or array elements. So I want to use my debugger to peek and make sure I'm doing this in the most logical way, and it's hard when the object in question can't be found.
#32

[eluser]OverZealous[/eluser]
@BrianDHall

All of the related objects in DMZ are created via PHP magic methods. Actually, a lot of the stuff is magically generated. This has several very important benefits:

1) You don't waste memory and time creating unused objects.
2) You avoid infinite recursion ($user->usergroup->user->usergroup->user->...)
3) Autoloading is more intelligent - the objects are only auto-loaded the first time you access them.

The side effect is that many of the properties of a DMZ model are not visible to debuggers until the first time they are used.

Also, I haven't actually gotten a proper PHP debugger set up yet (I know - shameful), so I don't know if there are limitations [in the debugger].

Edited last sentence.
#33

[eluser]BrianDHall[/eluser]
Aha, thanks Phil - that makes sense now.

For those interested I worked out how to make it work with a single function either in the datamapper object, or you can make it into an extension to use in all of them if you are so inclined:

Extremely easy:

Code:
function get_parsable_array()
    {
        $i = 0;
        foreach ($this->all as $res)
        {
            foreach ($res->stored as $key => $value)
            {
                $return[$i][$key] = $value;
            }
            $i++;
        }

        return $return;
    }

So now you can easily do something like this:

Code:
$forum = new Forum(1);

$forum->threads->get();

$threads = $forum->threads->get_parsable_array();

$this->parser->parse->('view_here', array ('threads' => $threads))

And then you can do something like this in the view:

Code:
{threads}
{title}, last post {last_post_time}
{/threads}

Playing with the template class to minimize code mixing with HTML - purely because I hate all the <? ?> crap, reminds me of spaghetti code too much.


EDIT: I've noticed something highly annoying to me - while the parser does understand the previous code in a sort of foreach style with less coding, you can't follow it along with php code mixed in when necessary. So you can't stick in an if() to, say, turn a flag of whether or not a post is new into something other than its raw variable inside the {tag}{/tag} execution.

Seems like trading a case of dry scalp for crabs. No thanks.

LOL
#34

[eluser]tdktank59[/eluser]
Hey Pill having some issues with the extensions.

Code:
$n = new Note();
// It is highly recommended you load the note before saving.
$n->get_by_id($this->input->post('id'));

$related = $n->from_array($_POST, array('message', 'date', 'category'));
// $related includes any new categories that need to be saved.  At this point, $n may have had some old categories deleted.

// add a related editor
$related['editor'] = $logged_in_user;

// save with the related objects
if($n->save($related))
{
    // redirect after save
}

For some reason the $related is not being set as if the from_array is not passing off the data when set to a variable. The other method where I save with from_array($_POST,'',TRUE); works tho.
#35

[eluser]OverZealous[/eluser]
@tdktank59
That has nothing to do with the extensions. That's a normal related save. You probably have a misconfiguration in your relationships, or $logged_in_user is invalid.
#36

[eluser]tdktank59[/eluser]
[quote author="OverZealous" date="1260517896"]@tdktank59
That has nothing to do with the extensions. That's a normal related save. You probably have a misconfiguration in your relationships, or $logged_in_user is invalid.[/quote]

That was your demo
http://www.overzealous.com/dmz/pages/ext...array.html

Heres what I am using and it dosnt work (following your examples btw)
Code:
$c = new Customer();
        
        if ($_POST)
        {        
            $rel = $c->from_array($_POST, array(
                'first_name',
                'last_name',
                'address',
                'city',
                'state',
                'zip',
                'country',
                'phone_number'
            ));

            $rel['custom_id'] = 'C'.random_string('alnum', 11);
            if ($c->save($rel))
            {
                $this->session->set_flashdata('success', 'The Customer has been created');
                $this->session->set_flashdata('customer_id',$c->id);
                redirect('customers');
            }    
        }
        
        echo $c->render_form(array(
                'Customer' => 'section',
                'first_name',
                'last_name',
                'address',
                'city',
                'state',
                'zip',
                'country',
                'phone_number'
            ),
            'customers/create',
            array(
                'save_button' => 'Save',
                'reset_button' => 'Clear'
            )
        );


EDIT: Never Mind it works... My relations were screwed up since I hadnt setup one of the models yet.
#37

[eluser]Mirage[/eluser]
Hi there - new challenge:

How to I save additional fields into a join table?

I've looked at the bugs example application (though not a most recent version). The bugs_users join table has two extra fields: is_owner and is_complete.

However the example app makes no use of these fields, so I can't peek. :-) Say I created a bug, which would make me the owner, then how would I set the is_owner field in the join table?

My particular need is that I have plants and collections of plants. In plantcollections_plants join table, I'd like to assign a specific 'display_title' to the plant, only used for that collection. How do I do that?

Thanks,
m
#38

[eluser]OverZealous[/eluser]
@Mirage
Look in the docs, under Working with Join Fields
#39

[eluser]OverZealous[/eluser]
Status Update:

For all those interested, I started an RSS feed for DMZ updates.

Just visit any of the doc pages and click the RSS feed icon in your browser. If the link doesn't show up, you probably need to refresh or force-refresh (SHIFT+F5) the page.

Alternatively, the feed is explicitly linked on the changelog or download pages.

I also added a few items to the manual (specifically in the troubleshooting section). Nothing major, but hopefully they will help with debugging.
#40

[eluser]Mirage[/eluser]
[quote author="OverZealous" date="1260527291"]@Mirage
Look in the docs, under Working with Join Fields[/quote]

There it is! Awesome, thanks!
-m




Theme © iAndrew 2016 - Forum software by © MyBB