Skip to main content
Known Participant
January 11, 2019
Answered

CFDUMP - hide option

  • January 11, 2019
  • 4 replies
  • 870 views

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 has been closed for replies.
    Correct answer BKBK

    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>

    4 replies

    BKBK
    Community Expert
    Community Expert
    January 13, 2019

    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

    fgwengerAuthor
    Known Participant
    January 14, 2019

    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>

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    January 14, 2019

    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>

    Charlie Arehart
    Community Expert
    Community Expert
    January 12, 2019

    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?

    /Charlie (troubleshooter, carehart. org)
    BKBK
    Community Expert
    Community Expert
    January 12, 2019

    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>

    Community Expert
    January 11, 2019

    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

    Dave Watts, Eidolon LLC