Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cfdump component method values, not component structure

I have recently started using a cfc component to store user information in the Session variable. I used to store them as individual variables in Session, such as Session.UserId, Session.Firstname, or Session.Lastname. This new component nicely wraps that all up for me into a component with get methods for each value I need (i.e. Session.User.getUserId(), Session.User.GetName(), etc).

But when I do a cfdump of the session variable for debugging, it displays the object structure's metadata. I'd like to see the values returned by the component's get methods. Any way of using a cfdump to output the function values with the object metadata?

like image 774
Sam M Avatar asked Jan 25 '26 22:01

Sam M


2 Answers

<cfdump> isn't magic, all it does is output the value you give it. As your CFC instance doesn't expose any public properties reflecting these values, <cfdump> hasn't got any way of knowing what they are.

If you need to extract all the private properties reflecting your former session scope in one hit, then you need to create a method to do so, and then <cfdump> that. EG:

public struct function getVariables(){
    return  variables;
}

If you are abstracting the values you want further, eg into variables.sessionStuff (variables.sessionStuff.userId, variables.sessionStuff.name etc), then write a method getSessionStuff() which returns variables.sessionStuff.

like image 172
Adam Cameron Avatar answered Jan 27 '26 10:01

Adam Cameron


Any way of using a cfdump to output the function values with the object metadata?

Yes, use accessors.

<cfcomponent accessors="true">
    <cfproperty name="userID">
    <cfproperty name="firstName">
    <cfproperty name="lastName">
</cfcomponent>

Try to <cfdump> this object, you'll see the property values.

like image 34
Henry Avatar answered Jan 27 '26 11:01

Henry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!