1 Reply Latest reply: Jun 26, 2012 8:16 AM by CF-AXL RSS

    CFC Implicit notation

    community help Community Member
        • 1. Re:  CFC Implicit notation
          CF-AXL Community Member

          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.





            this.name = "MyApplication";

            this.invokeImplicitAccessor = true;





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


            <cffunction name="getFirstname">

              <cfreturn variables.firstname>






              emp = new employee();

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

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



          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.