What is best practice for things like table row lo...
# box-products
d
What is best practice for things like table row looping from a record set? Is that to be kept out of the view? In the model?
g
I typically do UI stuff in the view, so if I had a query result provided to it, I let the view loop over it. I have seen people abstract out doing that in the model and then returning the HTML to render, but I think its easier to let the views do what they need.
👍 2
a
I have seen people abstract out doing that in the model and then returning the HTML to render
Did you kill those people?
😆 1
g
The ones that do that or the ones that don't do that? You are being vague sir. 😄
a
Kill them. Kill them all.
(fixed)
g
It looks like someone has a case of the Thursdays today... 😛
a
Seriously though Derek... if all yer doing is looping over the records to output them and/or format-them-for-output and then output them: view. If your loop performs any other logic on the values... model. And then loop again to just output them in the view. If that makes sense.
Ah dude look at my thread in Lucee.
(but I will not pollute this thread with that stuff).
d
Thanks
a
Copy code
<!--- in the view --->

<!--- good --->
<cfloop query="stuff">
    #someSimpleValue# #someDateValue.dateFormat("yyyy-mm-dd")#<br> <!--- that's just display logic. All good --->
</cfloop>


<!--- bad --->
<cfloop query="stuff">
    #someOtherObject.doSomeMoreProcessing(someValue)#<br> <!--- that's business logic, so does not belong in a view --->
</cfloop>
👍 1
☝️ 1
d
Sounds good.
oh so what about if I have a function that just changes a badge color?
setRejectListBadgeColor(rcd.reason)
g
I'm still ok doing that in a view if its simpler
3
d
ok, maybe stupid question, but how do you access a model function within a view?
r
service = new <http://models.my|models.my>.awesome.Service();
assuming a cfscript block at the top of the page
then
#service.doSomething()#
on the page
g
Is the logic hitting a database or is just just a UDF for display purposes? If a simpler UDF for display, you can always put it in ApplicationHelper.cfm.
👍 1
a
how do you access a model function within a view?
You don't (not a ColdBox answer; and MVC one). ApplicationHelper.cfm sounds like something CFWheels would implement / misuse to put uncategorised UDFs into a special magic global space that is inappropriate for almost all situations, and is jut bad app design. I could see how there might be some view helper libs that could be exposed to all views (eg: RomanNumeralHelper or something specifically view-ish), but that would make no sense being exposed everywhere. But I'll double-down on the notion that any functionality that does anything more than format a value for display should not be called from the view layer. And the formatting functionality should have no side effects.
👍 1
d
it's specifically for display purposes only
the applicationhelper.cfc works like a champ, but you're right, I don't need it exposed everywhere so I just put it in indexHelper.cfm
2
g
I actually should have suggested indexHelper first, good call. 🤘