How do you call the model from LightFront?
LightFront allows you to call the model as you do in any ColdSpring or Lightwire based application, but you can also take advantage of a couple of key functions.
Initially, LightFront didn't deal with the model at all, but in 0.3.6, we added functionality to call services and other components:
- initService() - Use this function in your controllers to initialize services. If the service has not been instantiated, it instantiates it. There is an optional true/false parameter to load the service into the application scope. The default value is set to yes. You use this like you would call ColdSpring. e.g. <cfset variables.userService = initService("user")>. You would then call the service later in a function: e.g. <cfset foo = variables.userService.read(arguments.args.id)>.
- initComponent() - Use this function like you use initService, but you'd typically use this function inside services to call DAOs, gateways and other objects but please... please don't fall into the 5 for 1 CFCs per object anti-pattern. Brian Meloche, the LightFront author, recently spoke about this tendency at CFObjective, and will be presenting it to the ColdFusion Meetup soon. That said, if you want to use initComponent, set it in the application scope, so that you may call the component in the service without needing to extend LightFront, such as: In onApplicationStart(): application.lfront.initComponent = initComponent; and, in your service: variables.userDAO = initComponent("model.user.userDAO").
