Question

All of my FW/1 controllers extend extend base.cfc. In base.cfc there is a function called addMessage(). Messages are thing like "You have successfully logged in". "There is an error in your data", "Error occurred while processing request.

The addMessage() appends messages to a variable called request.arMessage (an array). When I get to the layout file, the layout file loops through all the message and displays them on the page.

I am considering replacing request.arMessage with request.qryMessage. That way I can run a QoQ and sort by severity as opposed to last in last out. See below

void function addMessage(required string message, numeric priority=0) output="false"    {

param request.qryMessageQueue = QueryNew("Priority,Message", "integer,varchar");

QueryAddRow(request.qryMessageQueue);
QuerySetCell(request.qryMessageQueue, "Priority", arguments.priority);
QuerySetCell(request.qryMessageQueue, "Message", trim(arguments.message));
}

Is this approach consistent with how MVC and FW/1 should be doing this?

Was it helpful?

Solution

I can't speak for the requirements of MVC or FW/1, but I can tell you how to do this is your cfc.

Instead of building an array, build a query object. Then use your Q of Q to sort it. Then use a combination of ListToArray and ValueList to create your sorted array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top