开发者

Is there a ColdFusion equivalent to PHP for include_once?

开发者 https://www.devze.com 2022-12-25 03:15 出处:网络
I\'ve been adding this to my pages: pagewithinclude.cfm <cfinclude template = \"_pag开发者_如何学JAVAename.cfm\">

I've been adding this to my pages:

pagewithinclude.cfm

<cfinclude template = "_pag开发者_如何学JAVAename.cfm">

_pagename.cfm

<cfif Not IsDefined("variables.included_pagename")>
<cfparam name = "variables.included_pagename" default = "1">

rest of page

</cfif>

Is there a better way in CF? Something similar to PHP's include_once?


Nope, what you've done is probably the best way to do it. Although I'd use a Request variable instead.


This question was asked in 2010 (and many answers were then or 2011). Since then, in 2012, CF10 added the optional runOnce attribute for CFINCLUDE (or its script equivalent). Marques had added a mention of that attribute in a comment on the original question, in 2016, but it could be missed as an "answer".

I was helping someone who was seeking a solution to this problem, and I found this discussion, but noticed its lack of a clear answer. (And while there may be technicalities that distinguish CF's runonce from PHP's include_once, they are close enough in concept that it seems worth pointing out, even if it may not be the exact solution to the OP's question--if they even cared, now 10 years later.)

0

精彩评论

暂无评论...
验证码 换一张
取 消