viewtopic.php?t=75264
This time I ask. Suppose I have a model which pulls on a table which contains several fields, one of which is a timestamp (I convert all date/time to UNIX timestamp when storing in DB).
That date needs:
1) To be converted to a format according to user's locale settings
2) To be converted from a human friendly format to a timestamp
#1 could be done in the view, but would require the View to have access to the users locale object. Alternatively, it could be done in the model (where in my case it currently is) which at least has the benefit of formatting the date in human readable fashion no matter where the Model is used (severl other views use it).
Both of these instances have the one drawback. The make the model/view depedent upon what I would consider application specific functionality - the locale object.
For this reason, I am tempted to refactor the formatting code from the DB and put it in the controllers instead. Likewise, instead of passing the date as a formatted string, I would convert the string (using the locale object) into a timestamp before passing that data to the Model.
The problem with using the controller in this regard is that I loose some application level reuse at the gain of a more generic mode/view class. Under the context of my application I get more code reuse when it's in the model, then I do if it's in the controller.
If I have 2 controllers which use my model, then each of those two controllers needs to format/convert the date from one format to the other. One before sending the date to the model and one before sending a timestamp to the view for rendering.
If I have this logic inside my model, the anytime I call that model the date is formatted for me *BUT* again this comes at the expense of having to somehow have the model be aware of a locale object, which is initialized with user details. If the model is now depenendent upon the locale object, it looses it's re-usability in other projects, if the next application doesn't need locale information, we have code which serves no purpose.
I have considered several techniques to minimize the dependency:
1) Use DI to avoid conrete dependency.
2) Access the registry from within the model so we can access the locale object - which now creates two dependecies (one on the registry and one on locale).
Should I refactor the code for formatting into the controllers and just accept the loss of code reuse at the expense of more logic code or something entirely different???
Cheers