3

Should a view call a helper function?

Say I pass in data from the DB to the view. The data is a unix timestamp. Should I make a call in my view to convert it to a human readable TS or should I convert it in the controller before passing it in? OR should I make a method in the model that converts...

Looking for a "best practice" or "secure coding" concerned answer.

asked Jun 27, 2014 at 19:33

2 Answers 2

2

This seems like a fairly trivial calculation, indeed, you could implement it in a few lines of javascript. It is your view that is in charge of displaying data; let it do its work.

answered Jun 27, 2014 at 19:40
2
  • You are right... and I guess I couldn't come up with a better example. Maybe the question should be "When should you do each"? Commented Jun 27, 2014 at 19:49
  • 1
    @Jeff: The view is responsible for massaging the data into the right form for display and that can include some calculations. Any calculations not related to displaying the data should go into the model. Commented Jun 28, 2014 at 6:24
0

Since human readability depends on the target output device (big screen TV, dashboard display, watch face, voice synthesis, Morse code tones/blinks, etc.), it might be best to customize this readability in the object most closely associated with the physical output device, likely the view object. The model objects can keep and pass on a binary encoded or computationally suitable form.

answered Jun 28, 2014 at 19:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.