CFdump cfcomponent cfscript

房东的猫 提交于 2020-01-03 12:47:11

问题


Can one use cfdump inside a cfcomponent? Can one use cfdump inside a cfscript?

I know the anser is no then how can one emit the values of the functions insde cfcomponent cfscript? I am using CF8


回答1:


Can one use cfdump inside a cfcomponent?

Yes, with some caveats. If you use a CFDUMP followed by CFABORT, the dump will be displayed whether or not the component/method has output turned off. That does, of course, abort all processing.

Can one use cfdump inside a cfscript?

Not exactly (unless you're using CF9), but there are workarounds.

You can close your script, put in the dump tag, then re-open it, like so:

</cfscript><cfdump var="#myVar#"><cfscript>

There is also a UDF at CFLib that mimics the CFDUMP tag.

Dump

Added: In CF9 or later, there is also writeDump().




回答2:


Coldfusion 9:

<cfscript>
    myVar = "this is a test";
    WriteDump(myVar); 
</cfscript>

Coldfusion 8 and below: CF 8 does not have a cfscript version of the tag, so if needed, it needs to be abstracted into a user defined function first. This function will need to be accessible to your component.

I avoided the name "WriteDump()" to prevent any possible conflict if this code is used with CF9.

<!--- Abstract cfdump tag for use in cfscript --->
<cffunction name="scriptDump" output="no" hint="Abstracts cfdump for cfscript">
    <cfargument name="myVar" required="yes">
    <cfset var result = "">

    <cfsavecontent variable="result">
        <cfdump var="#arguments.myVar#">
    </cfsavecontent>

    <cfreturn result>
</cffunction>

<cfset myVar = "this is a test">

<!--- Test the scriptDump(var) function in cfscript --->
<cfscript>
    dumpOfMyVar = scriptDump(myVar);
</cfscript>

<!--- Test the scriptDump(var) function in regular HTML --->
<cfoutput>
    #scriptDump(myVar)#
</cfoutput>



回答3:


cfdump inside cfcomponent? why not... But I think you should do it in a cffunction.

cfdump inside cfscript? WriteDump() in CF9, or search cflib for a UDF that works in CF6+




回答4:


You can only use writeDump in CF9. If you're in CF8, use this:


adminapi = createObject("component","cfide.adminapi.base");
adminapi.dump(foo);


来源:https://stackoverflow.com/questions/1917706/cfdump-cfcomponent-cfscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!