What is setMethod() and populateModel() in coldbox framework

250 Views Asked by At

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");
}
1

There are 1 best solutions below

0
Gavin Pickin On

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.