开发者

Parsing text in MVC

You have a blog.

You want certain combinations of symbols (i.e. :), :(, :p ...) to开发者_C百科 be parsed into emoticons before the post in the blog are printed on the screen.

Should this parsing be a responsibility of the Model, the View or the Controller?


Use a View Helper. The helper should have a function that parses for the emoticons.

Think of this parsing as formatting for output, therefore, it should be handled in the View.


Do you want to store them parsed or raw?

If the former, the controller or model, depending on how fat or thin you are. If the latter, the view.


If you want to store them raw, then it belongs to the View.

A View Helper is one choice. Another would be a custom ob_handler that post-processes the rendered HTML before it is delivered. Since you mentioned, the post might also contain BBCode, you could also consider using a BBCode parser, which would handle the emoticons as well.

Personally, I think emoticons are so useless, that the server shouldnt be bothered with it. So I'd probably put that responsibility in a JavaScript that will parse and replace on page load. Did a quick Google and think you could use http://benalman.com/projects/javascript-emotify/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜