When to include helper methods in a model (MVC)?

I think the easiest way to ask this question is the real real situation that I am facing.

In our system, we have a site model (the classic MVC structure here), which represents a row in our site table. One of the fields in the site table that is stored in the site model is the time zone of the site. We use this to adjust the UTC time from the database to the site’s displayed time zone. There are several helper methods that help with this: utcDatetimeToSiteTimestamp (), utcTimeStampToSiteDatetime (), etc.

Since these helper methods use the time zone of the site, which is stored in the site model, can these methods be included in the model? Or should they be placed in a separate helper class or something else?

I know that models should do more than just hold a row of data from a database, but where is the line between helper methods that act on this data versus helper methods that use this data to work on an external input?

Thank you for understanding!

+3
source share
4 answers

. , , . , .

+6

. , , , .
. . -, .

+3

, . , , , .

+1

, . - , , ( , ). , . , BlogPost, getOneCompiled() , .

It is important that you look at your options and see what leads to the creation of code that is easy to read and maintain. Writing a helper function in this native file may take a little more work, but if it makes managing your code easier, it's definitely worth it.

+1
source

Source: https://habr.com/ru/post/1717297/


All Articles