I’m got a CFC whose properties I want to return through a single function:
public string function getApplicationSetting(required string setting)
{
return myCFC.getSetting()
}
The problem is that Setting needs to be dynamic. If it were a struct, I could do this:
return myCFC.variables[arguments.setting]
In other words, the Setting in getSetting() needs to reflect the incoming argument. Am I approaching this wrong? Is there a better way to do this?
Assuming you are in ColdFusion 8, you’ll want to look at the onMissingMethod() function in ColdFusion.
Something like this untested example I just wrote up:
If you are in ColdFusion 9, then implicit getters are already a part of the deal if you define your properties correctly.
The above component will automatically have getLastname(), getFirstname(), etc.
Reference: http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/