Inheritance not working with cfinclude

时间:2016-06-10 16:09:39

标签: coldfusion cfwheels

I am trying to resolve an issue on CFWheels, where I am have trouble extending my parent Application.cfc which also extends another Application.cfc. In order to understand the problem better and really single out what's going wrong, I have created a directory structure as follows:

/mainapp/index.cfm
-------------------------------------------------
<cfoutput>
    <cfdump var="#session#">
</cfoutput>

/mainapp/Application.cfc
-------------------------------------------------
<cfscript>
    component
    {

        this.name = "Main App";
        this.applicationTimeout = createTimeSpan(0, 1, 0, 0);       
        this.sessionManagement = true;
        this.sessionTimeout = createTimeSpan(0, 0, 30, 0);

        public function intMainApp(name, value){
            session[name] = value;
        }

        public boolean function OnApplicationStart(){
            //Handle OnApplicationStart Callback
            return true;
        }
        public void function OnApplicationEnd(struct ApplicationScope=structNew()){
            //Handle OnApplicationEnd Callback
        }
        public void function OnRequest(required string TargetPage){
            //Handle OnRequest Callback
        }
        public boolean function OnRequestStart(required string TargetPage){
            //Handle OnRequestStart Callback
            include arguments.TargetPage;   
            intMainApp("mainappv1", "something session");
            return true;
        }

        public void function OnSessionStart(){
            //Handle OnSessionStart Callback
        }
        public void function OnSessionEnd(required struct SessionScope, struct ApplicationScope=structNew()){
            //Handle OnSessionEnd Callback
        }
    }
</cfscript>

/mainapp/submainapp/index.cfm
-------------------------------------------------
<cfoutput>
    <cfdump var="#session#">
</cfoutput>

/mainapp/submainapp/Application.cfc
-------------------------------------------------
<cfscript>
    component extends="mainapp.Application"
    {

        this.name = "Main App";
        this.applicationTimeout = createTimeSpan(0, 1, 0, 0);       
        this.sessionManagement = true;
        this.sessionTimeout = createTimeSpan(0, 0, 30, 0);

        public function intSubMainApp(name, value){
            session[name] = value;
        }

        public boolean function OnApplicationStart(){
            //Handle OnApplicationStart Callback
            return true;
        }
        public void function OnApplicationEnd(struct ApplicationScope=structNew()){
            //Handle OnApplicationEnd Callback
        }
        public void function OnRequest(required string TargetPage){
            //Handle OnRequest Callback
        }
        public boolean function OnRequestStart(required string TargetPage){
            //Handle OnRequestStart Callback
            include arguments.TargetPage;   
            intSubMainApp("submainapp2", "var var 2");
            intMainApp("v3", "var 3");
            return true;
        }

        public void function OnSessionStart(){
            //Handle OnSessionStart Callback
        }
        public void function OnSessionEnd(required struct SessionScope, struct ApplicationScope=structNew()){
            //Handle OnSessionEnd Callback
        }
    }
</cfscript>

/mainapp/submainapp/childapp/index.cfm
-------------------------------------------------
<cfoutput>
<p>Testing Child App</p>
</cfoutput>

/mainapp/submainapp/childapp/Application.cfc
-------------------------------------------------
<cfcomponent output="false">
    <cfinclude template="../Application.cfc">
</cfcomponent>

If I execute the childapp/index.cfm I get the error.

Variable INTMAINAPP is undefined.

This problem is similar to the issue that I facing with cfwheels when trying to extend my parent Application.cfc. Why is it that InitMainApp method not being included in submainapp/Application.cfc when it used via cfinclude tag and Is there a workaround or fix for this problem.

Just as a clarification, childapp/Application.cfc is trying to include submainapp/Application.cfc

Moreover there is a issue created on this in the cfwheels community forums.

https://groups.google.com/forum/#!topic/cfwheels/1eMGLGSrbBY

0 个答案:

没有答案