Skip navigation
Currently Being Moderated

CFC Implicit notation

Jun 26, 2012 7:49 AM

 
Replies
  • Currently Being Moderated
    Jun 26, 2012 8:16 AM   in reply to Community Help

    Code Corrections

     

    In employee.cfm

    emp = new emp(); => emp = new employee();

    writeOutput("last Name = " & emp.emp.lastname & "<br>"); => writeOutput("last Name = " & emp.lastname & "<br>");

     

    In employee.cfc

    <cfproperty name="lastname" type="string" setter="false"/> => <cfproperty name="lastname" type="string" setter="true"/>

     

     

    CFC Implicit notation works only if you set both invokeImplicitAccessor in the Application.cfc and accessors in the component to true.  Only setting up invokeImplicitAccessor to true sets values to the This scope of the component as same as when it's not defined.

     

    For example, this will give you the error "Element FIRSTNAME is undefined in VARIABLES" because FIRSTNAME is defined in the THIS scope instead of VARIABLES.

     

    Application.cfc

    component

    {

      this.name = "MyApplication";

      this.invokeImplicitAccessor = true;

    }

     

    employee.cfc

    <cfcomponent>

      <cfproperty name="firstname" type="string"> 

     

      <cffunction name="getFirstname">

        <cfreturn variables.firstname>

      </cffunction>   

    </cfcomponent>

     

    employee.cfm

    <cfscript>

        emp = new employee();

        emp.firstname = "Tom";  // The scope of firstname is THIS, not VARIABLES.

        writeOutput("First Name = " & emp.getFirstname());  // This generates the error.

    </cfscript>

     

    In order to fix the error above, replace <cfcomponent> in employee.cfc with <cfcomponent accessors="true"> so that the scope of firstname would be VARIABLES.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points