2

What are setMethod(parameter) and populateModel(string) in the given code of the ColdBox framework?

function addUser(event,rc,prc)          
{
    LOCAL.userBean = populateModel("userBean").init(5,prc.siteid,event.getValue('userid',0));
    rc.user = securityService.getUser(LOCAL.userBean);
    LOCAL.userBean.setMethod(3);
    rc.genderList=globalsService.getGlobals(LOCAL.userBean); 
    LOCAL.userBean.setMethod(7);
    rc.stateList=globalsService.getGlobals(LOCAL.userBean);
    event.setLayout("Window");
    event.setView("purchase/addUser");
}
Community
  • 1
  • 1
Basit Ali
  • 155
  • 6
  • 1
    https://coldbox.ortusbooks.com/the-basics/event-handlers/model-integration/model-data-binding – Shawn Jun 23 '19 at 21:46
  • 1
    https://coldbox.ortusbooks.com/ <<< A pretty good place to start for ColdBox info. – Shawn Jun 23 '19 at 21:47

1 Answers1

0

SetMethod() would be something specific to the UserBean itself. That isn't something in ColdBox.

PopulateModel although can do a lot more, is usually a way to populate a model by passing a struct. The populate model will loop through the keys in the struct, and if there is a matching property in the model, it will set it.

So model.setUsername( rc.username ) for example, if there is a key called username. PopulateModel assumes you're sending the rc scope in, but its usually best to validate, and add restrictions so someone can't pass a password via url and set that to a user for example.

Shawn's links are good ones, hope that all helps.

Gavin Pickin
  • 742
  • 3
  • 7