Sub Components
Sub Components
Since Lucee 6.0, you can create sub components - additional components defined in a .cfc file after the main component. Before this, CFML required every component to be in a separate file.
This is useful when a component needs closely-related sub components, like an Address component with a Person sub component inside.
Add components after the main one with the name attribute:
component {
function mainTest() {
return "main";
}
}
component name="Sub" {
function subTest() {
return "sub";
}
}
Access sub components using $ notation:
cfc = new MyCFC();
echo("main->" & cfc.mainTest());
echo("<br>");
cfc = new MyCFC$Sub();
echo("sub->" & cfc.subTest());
echo("<br>");