MVC最佳实践 [英] MVC best practice

查看:137
本文介绍了MVC最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC(我使用codeigniter),想知道我应该放一个cut_description函数。

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

我的模型检索列表事件包括其描述。如果说明太长,我需要在前n个字之后剪切它,并添加一个阅读更多链接,因此视图不会太混乱。

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.

最佳做法是什么?


  1. 在模型之后添加用于剪切n
    个字词的逻辑

  2. 添加逻辑到控制器

  3. 将它添加到视图?

我认为3将是更容易(我不得不循环通过结果),但我不确定这将符合MVC。

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

您认为如何?

推荐答案

为了正确地显示 ,它应该进入视图。

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.

这篇关于MVC最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆