如何在ColdFusion中调用带有一些参数的cfm文件?

Dee*_*dhy 4 coldfusion coldfusion-9

是否可以使用某些URL参数从另一个cfm文件调用cfm文件?

cfinclude不起作用,因为它只包含内容..

Ste*_*her 15

使用a时<cfinclude>,您将要包含的页面中提供调用该文件的页面中的任何可用值.

所以你基本上可以传入变量而不是URL参数,并实现相同的功能.但是,您必须在include之上声明变量.

example.cfm

<cfset x = 5 />
<cfinclude template="derp.cfm" />
Run Code Online (Sandbox Code Playgroud)

derp.cfm

<cfif IsDefined("x")>
    <cfoutput>#x#</cfoutput> //this should output 5 since it was declared before the include
</cfif> //always good to make sure they're defined first
Run Code Online (Sandbox Code Playgroud)

  • (旁注:最好使用`structKeyExists`,比'IsDefined`更精确.) (4认同)