MVC - who decides what to do if there was no content?

When loading a page that lists, for example, events from the database, but no events are happening now, what solution should be to show the message "sorry there are no events happening now ..."?

  • If the model checks if the array is empty with events and call the view that contains this message as static content
  • Or is it necessary to check that the array with the content is empty, and if so, displays a message informing the user?
  • Or is this opinion based on and dependent on personal preference?
  • If it's based on personal preference, what are some of the advantages and disadvantages of any method?

EDIT: The same question can be applied to: we are trying to load an event, but the event has ended, so it will say "Sorry, this event has already ended." Again: choosing a model or choosing an option to say it?

+3


source to share


2 answers


The view is part of the triad that will know there is no content when the specified query requests a list of active events from the model layer and returns nothing.

If you look at this in the context of PHP, your view will not observe the model layer and will need to initiate a request for data.



Also, if you are really not sending anything back, then the same view should also set the response code to 204 .

+2


source


When to show which kind of message is obviously a view choice. The model does not know anything about the users reading the messages, but only about its internal state.

The actual question is how the view knows when to determine which message should be shown. Basically I mean two ways:



  • The view views the state of the model every minute / second / millisecond / when user-click-button / independently and refreshes messages as needed, or
  • The model itself emits events when its state changes, and the view listens for these events. But a model emitting an event that said "my state has changed" is something completely different from the decision to show a message to the user, and both must be strictly separated.
+2


source







All Articles