News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

loadMemberData(); and loadMemberContext();

Started by Matthew K., February 15, 2011, 11:59:39 PM

Previous topic - Next topic

Matthew K.

I am using loadMemberData(); and loadMemberContext(); both in Display.php, feeding an ID into the functions, and I return $user_profile[$row['member_name']]['name'] into another variable.

My code:
global $user_profile;
loadMemberContext($row['id_member']);
loadMemberData($row['id_member'], false, 'minimal');

The problem is, it shoots an error into the error log: loadMemberContext(): member id 2 not previously loaded by loadMemberData()

If I reverse the order, it messes up a bunch of the posting template, resulting in a LOT more errors.

Kays

loadMemberData() is called first. The ids should be in an array. See if this works:


loadMemberData(array($row['id_member']), false, 'minimal');
loadMemberContext($row['id_member']);

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Matthew K.

48 Undefined Errors from the looks of it, different variables.

What my guess is, is that by loading minimal, it's unsetting another call to memberData, or whatever.

Kays

I don't know then. It's been a while since I've used it.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Matthew K.

Yeah me too. And I am extremely tired, so I figured I might as well post and see what I am doing instead of digging for a while.

I reviewed the functions in the SMF Function Database, to make sure I had them right, except for the missing array() around the user id. And then I also even looked at the functions themselves to see what was triggering the error.

I can't seem to figure this one out.

texasman1979

If you have a list of ids, pass them loaddata, them pass a specific id to load context. There may be an error of re init. If you could pass along a definition of your objective, it may be more clear the logic. I hope this helps.
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


Matthew K.

Wait a second. I think I figured it out. I must have been really tired...I'll take a peak at it shortly and see if I am right, but I think I am.

Arantor

You can't run loadMemberContext off type 'minimal' in loadMemberData, needs to be either 'normal' or 'profile' for loadMemberContext to work.
Holder of controversial views, all of which my own.


Matthew K.

So if I just run loadMemberData with type 'minimal' how would I pull that stuff? Is it fed into an array somewhere?

Arantor

It's pushed into the global $user_profile array, e.g. loadMemberData(1, false, 'minimal') loads it into $user_profile[1]. (No you don't have to explicitly make it an array, it's capable of dealing with that)
Holder of controversial views, all of which my own.


Matthew K.

So really then, I just need to use loadMemberData since the only thing I am trying to pull is the members name based on their ID?

Arantor

If you're doing that, you could almost do what SMF normally does and just join from your table to the members table to get real_name that way.
Holder of controversial views, all of which my own.


Matthew K.

That's what I was starting to wonder about. That'll probably be a lot easier than loading Member Data for each member, and feeding it into an array of member names.

I'm going to go ahead and mark this topic as resolved since I figured out my problem, and am no longer going to use this method in this scenario anyways.

Thanks for the posts guys.
Labradoodle-360

texasman1979

One other thing is, if u actualy need user profile populated, great, but if it is an instance of just needng afew fields based off a user, you can more easily create ur own function to pull that specific data and not run big smf functions possibly a second or third time. But this is just an add seeing as I have no idea what ur up to.

Please forgive my ramlings, on fone at work and can't work on my own code, might as well debate logic with my friends here. :)
SMF 2.0.4
SimplePortal 2.3.5

LOGIC is a FOUR letter word! :)


Arantor

If you just need a few fields of a user, don't even bother making a function, just do a table join.
Holder of controversial views, all of which my own.



Advertisement: