Search code examples
coldfusion

Difference between cfc and cfm in ColdFusion


Hello could someone tell me what is the difference between .cfc & .cfm in ColdFusion? Also is there any differences related to Lucee?

I found some information here, but in my opinion it not answering about any differences for cfc & cfm if using Lucee: https://www.learncfinaweek.com/ https://community.adobe.com/t5/coldfusion-discussions/difference-between-application-cfc-and-cfm/td-p/522654


Solution

  • cfc stands for ColdFusion Component. cfm stands for ColdFusion Markup.

    There is a lot of overlap in the concepts but the important difference is that a cfm file is generally referred to as a "page" and is similiar to an html page but with access to ColdFusion tags.

    This is an exmaple cfm page

    <cfoutput>
    <h1>Hi, the time is now #now()#</h1>
    </cfoutput>
    

    A cfc file is used to represent a single component or object. This might look like

    component {
      public function init(){
        return this;
      }
    
      public function sayHi(){
        return "Hi";
      }
    }
    

    They serve different purposes but often they will be used together. For instance, one might handle a request with a single cfm page but then create multiple components that live in separate cfcs in order to do all the work on the page.