I'm working on a report that displays information about our company's sales locations. One of the bits of information is the 'last visit date' of the location. If the location has never been visited, I have to display (in the current language) 'Never' in red. There are several values like this one, this is just the example I'm using.
Currently my location model returns NULL (direct from the database) if the location hasn't been visited.
So my question is, do I use the
With #3, I think that is the most flexible. But is this simple case too soon to add that advanced functionality?
Any ideas are very appreciated!
Note: Our company's framework is some in-house PHP framework written many years ago.
Since the view has to examine the value anyway to determine whether it should be red or not, I see no reason not to let it deal with null
directly. After all, the "Never" is a display detail.
Option 3 would be the best decision. The model should be responsible for all of the data values, the controller the business logic, and the view presentation.
It's always a good idea to keep the views as simple as possible and avoid embedding code in them. While you could do handle this in the controller it would need to be duplicated in each controller which utilizes this model. That could create problems down the road if you needed to make a change.
It's the responsability of the model to give meaningful data. In your case null is probably as meaningful as you can get. My approach to MVC (there are as many approaches as people using MVC) is to use a ViewHelper class: 1) to decouple view and model 2) to return data to the view in a way optimized for presenting
Note: Different views can have different ViewHelpers. Note: $this->salesLocations->lastVisit would pass by a SalesLocationViewHelper method.
hope this makes sense