Skip to main content
Known Participant
Jan 11, 2019 8:22 PM UTC
Answered

CFDUMP - hide option

I am trying to figure out how to reference a 2nd level key within a structure for the purpose of hiding it within a CFDUMP.  If I just CFOUTPUT it, I can use one of these references and the value outputs perfectly:

- #test.level1.level2#

- #test["level1"]["level2"]#

But if I don't want CFDUMP to output test.level1.level2, I can't get it to work (e.g. hide='what?').  I've tried these permutations, with no success.

- level1.level2

- test.level1.level2

- level1["level2"]

- test["level1"]["level2"]

Any ideas?  Thanks.

    This topic is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Jan 14, 2019 7:44 PM UTC

    fgwenger  wrote

    // Dump while hiding the key "level2"

    writedump(var=test, hide="[what do I put here to hide 'level2'?]");

    My guess is that you cannot use the hide attribute in this way. That is because the value of the hide attribute must be a key or list of keys of the structure to be dumped.

    In your example, test has one key, level1. If you hide it, test["level1"]["anotherLevel2"] will be hidden.

    But you could solve the problem differently. Use an approach similar to the one I gave at the beginning:

    <cfscript>

    test["level1"]["level2"]=1;

    test["level1"]["anotherLevel2"]=2;

    // store copy of the original struct, in case you need it later

    testCopy=duplicate(test);

    // delete the test.level1.level2

    structDelete(test.level1, "level2");

    writedump(test);

    </cfscript>

    8 replies

    BKBK
    Community Expert
    Community Expert
    Jan 13, 2019 11:21 AM UTC

    Good question from Charlie. I had assumed all keys in level 2 are to be hidden.

    fgwenger​ , rereading your post once again, following Charlie's question, it is now clear what you ask. You wish to know how the hide attribute works. The answer is:

    <cfscript>

    test["level1"]["level2"]=1;

    test["level1"]["anotherLevel2"]=2;

    // Dump while hiding the key "level2"

    writedump(var=test["level1"], hide="level2");

    </cfscript>

    Remember, the key is hidden when you dump test["level1"], but is visible when you dump test

    Translate
    fgwengerAuthor
    Known Participant
    Jan 14, 2019 4:21 PM UTC

    I want to dump "test", but hide "level2" (and still show "anotherlevel2"). 

    <cfscript>

    test["level1"]["level2"]=1;

    test["level1"]["anotherLevel2"]=2;

    // Dump while hiding the key "level2"

    writedump(var=test, hide="[what do I put here to hide 'level2'?]");

    </cfscript>

    Translate
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Jan 14, 2019 7:44 PM UTC

    fgwenger  wrote

    // Dump while hiding the key "level2"

    writedump(var=test, hide="[what do I put here to hide 'level2'?]");

    My guess is that you cannot use the hide attribute in this way. That is because the value of the hide attribute must be a key or list of keys of the structure to be dumped.

    In your example, test has one key, level1. If you hide it, test["level1"]["anotherLevel2"] will be hidden.

    But you could solve the problem differently. Use an approach similar to the one I gave at the beginning:

    <cfscript>

    test["level1"]["level2"]=1;

    test["level1"]["anotherLevel2"]=2;

    // store copy of the original struct, in case you need it later

    testCopy=duplicate(test);

    // delete the test.level1.level2

    structDelete(test.level1, "level2");

    writedump(test);

    </cfscript>

    Translate
    Charlie Arehart
    Community Expert
    Community Expert
    Jan 12, 2019 5:43 PM UTC

    You refer to hiding a key but you don't indicate having tried the hide attribute of cfdump (added in cf8) . Can you confirm if that did not work for you?

    Translate
    /Charlie (troubleshooter, carehart. org)
    BKBK
    Community Expert
    Community Expert
    Jan 12, 2019 4:42 PM UTC

    You could just clear the second level before dumping. For example,

    <cfscript>

    x["y"]["r"]=1;

    x["y"]["s"]=2;

    // store copy of original struct, in case you need it later

    xCopy=duplicate(x);

    // clear the second level

    structclear(x["y"]);

     

    writedump(x);

    </cfscript>

    Translate
    Community Expert
    Jan 11, 2019 10:25 PM UTC

    This is kind of difficult, because CFDUMP is designed to take a "top-level" variable so to speak and dump it in its entirety, so you can see all the delicious goodness inside. So, I think what you'd have to do is pass it by value to another variable, and dump that instead. If it's in an array, you should be fine doing something like this:

    <cfset dumpMe = test.level1.level2>

    then using CFDUMP with that.

    Dave Watts, Eidolon LLC

    Translate
    Dave Watts, Eidolon LLC