MVC best practice

允我心安 提交于 2020-01-03 20:07:13

问题


I'm new to MVC (i'm using codeigniter) and was wondering where I should put a "cut_description" function.

My model retrieves a list of events including their description. If the description is too long, I would need to cut it after the first n words, and add a "read more" link, so the view doesn't get too cluttered.

What would be the best practice?

  1. add the logic to cut after n words to the model
  2. add the logic to the controller
  3. add it to the view?

I think 3 would be the easier (I have to loop through results anyway), but I'm not sure this would comply with MVC.

What do you think?


回答1:


If you are modifying information to properly display it, it should go into the view.

I doubt it should be in the model primarily because if the data was always going to be shortened, you would probably would store it shortened.



来源:https://stackoverflow.com/questions/2574947/mvc-best-practice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!