如何检索enablecfoutputonly的当前值?

时间:2012-11-12 22:15:14

标签: coldfusion coldfusion-9

我们正在使用Coldfusion 9.

是否有一种简单的方法可以知道在特定请求期间enablecfoutputonly是否已设置为true?

1 个答案:

答案 0 :(得分:5)

我现在无法使用CF9进行测试,但在CF10中,可以通过检查输出对象从getPageContext()访问它:

<cfscript>
   out = getPageContext().getOut();
   // Is the cfsetting enablecfoutputonly value currently true?
   isSettingEnabled = out.getDisableCount() >  0;
   WriteOutput("isSettingEnabled="& isSettingEnabled &"<br>");
   // Is output currently allowed?
   isOuputtingEnabled = out.getDisableCount() == 0 || out.getOutputCount() > 0;
   WriteOutput("isOuputtingEnabled="& isOuputtingEnabled &"<br>");
</cfscript>

..或使用反射:

<cfscript>
    out = getPageContext().getOut();
    internalMethod = out.getClass().getDeclaredMethod("isOutputEnabled", []);
    internalMethod.setAccessible( true );
    isOuputtingEnabled = internalMethod.invoke( out, [] );
   // is output currently allowed?
    WriteOutput("isOuputtingEnabled="& isOuputtingEnabled);
</cfscript>