Who's responsibility is it to encode a string, the model or the view?
I've a string from a database, it's come from the user - I want to keep as a much information as possible in the database, so I'm saving the input verbatim.
When I come to display the string, should I be encoding it when I populate the view model, or should the view decide if it wants to display it encoded or not?
Thanks,
K
The View
The difference between the two is that The Model holds that data and The View is responsible for showing the data based on the output medium. Because if you wanted to transmit this data over some none HTML medium you probably don't want it HTML encoded.
I think this mostly pertains to how clean you'd like your View. If you encode on the view end you keep your controller free of data manipulation operations while muddling the view up with ugly script tags, however if you do it on the controller end you'll have a cleaner (more designer friendly) view and possibly confusing code in the controller.
The real question is would you rather muddle your back-end code or the view markup?
Generally speaking though I believe the best practice would be in your view so that your controller has the ability to morph to different output streams without changing how it operates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With