1

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

Saad A
  • 1,135
  • 2
  • 21
  • 46
  • Why are you trying to include the parent instead of trying to extend it? – Dan Bracuk Jun 10 '16 at 16:30
  • I mentioned that this is related to cfwheels issue. CFWheels application.cfc uses cfinclude tag so if I extend the parent application.cfc it throws an error "The routine onApplicationStart has been declared twice in different templates". This entire scenario is to resolve the real issue i am facing with cfwheels. – Saad A Jun 10 '16 at 16:33
  • What does cfwheels do with `component extends="mainapp.Application"`? – Dan Bracuk Jun 10 '16 at 16:37
  • mainapp is a login page, that introduces the user to other apps. Once your logged in it create a session with user information and other methods that are common functionality for child apps, one of these child apps is my cfwheels app. But the problem is if the inheritance doesn't work, I am not getting this common functionality methods in my cfwheels app and also the session information is not being transferred to my cfwheels app. – Saad A Jun 10 '16 at 16:42
  • Right, I'd say that as you are including `/submainapp/Application.cfc` from your `submainapp/childapp/Application.cfc`, when you do this then ColdFusion when it executes the template won't look at the `component extends="mainapp.Application"` bit (as an include is not intended for .cfc files). As such anything in `/mainapp/Application.cfc` will be ignored. Reading the formum you linked to then it sounds like you have ` ` in both Application.cfcs so it gets included twice. – John Whish Jun 10 '16 at 16:58

0 Answers0