Extender el Application.cfc a un subdirectorio

Para extender componentes lo normal es usar el atributo extends pero por cosas del coldfusion, no se puede extender el Application.cfc desde un subdirectorio así que toca hacer el truco del almendruco.

Si tenemos un Application.cfc en el raíz del tipo:

<cfcomponent displayname="Application" output="no" hint="Handle the application."> 
	<cfscript>
		//Variables de Application
		this.name = "Nombre_aplicacion";   
		this.Sessionmanagement = true;
		this.SetClientCookies  = true;
		this.Sessiontimeout = "#CreateTimeSpan(0,2,0,0)#";
		this.applicationtimeout = "#createtimespan(0,12,0,0)#";
		this.CustomTagPaths = GetDirectoryFromPath(GetCurrentTemplatePath());
	</cfscript>

	<cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
		<cfinclude template="application_variables_de_aplicacion.cfm" /> 
		<cfreturn true />
	</cffunction>
	
	<cffunction	name="OnSessionStart" access="public" returntype="void"	output="false"	>
		  <cfinclude template="application_variables_de_sesion.cfm">
		  <cfreturn />
	</cffunction>	
</cfcomponent>

Lo que hacemos es crearnos otro componente en el raíz que nos sirva de puente para extender el Application.cfc, en este caso lo llamaremos ApplicationProxy.cfc

<cfcomponent name="ApplicationProxy" extends="Application">
</cfcomponent>

Y ahora en el Application.cfc del subdirectorio si podremos extender el ApplicationProxy.cfc y así heredar Application.cfc del raíz

<cfcomponent name="Application" extends="ApplicationProxy">
	<cffunction name="OnRequestStart" access="public" returntype="boolean" output="true" hint="Fires at first part of page processing.">
		<!--- control de la sesion para que no se cuelen sin logar --->
		<cfset lista_pags_no_requiere_login = "login.cfm,recordar_contrasena.cfm">
	    <cfif not StructKeyExists(session, "logado") and (FindNoCase(GetFileFromPath(GetBaseTemplatePath()),lista_pags_no_requiere_login) eq 0)>
	        <cflocation url="login.cfm" addtoken="no" />
	    </cfif>	    
		<cfreturn true />
	</cffunction> 
</cfcomponent>
Dejar un comentario?

1 Comentarios.

  1. Tony,No, that’s usually the way I do it to apply trinaactsonality to all my beans. There are performance implications with proxying methods, particularly around the initial load (because of the filesystem/compiler churn), but it’s snappy enough at runtime.The particular case that drove this class was an app where every method is proxied for trinaactsonality, but a single method on a single bean needed to be non-transactional (it manages it’s transactions manually with CFTRANSACTION and a single method invocation encapsulates several distinct transactions.

Deje un comentario


NOTA - Puede usar estosHTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.