Mvc,php,symfony 1.4:为视图格式化数据,在哪里放?

时间:2013-05-16 13:16:20

标签: php model-view-controller symfony-1.4

让我们想象一下这个架构:

model: get record and joined records
controller: iterating through all the records, and doing some calculations, statistics calculations even formatting dates etc
view: show it
好吗?我猜不会。但模型只能处理数据检索 - 而不是格式化。控制器也不能这样做。在哪里做“迭代所有记录,进行一些计算,统计计算甚至格式化日期等”部分?

1 个答案:

答案 0 :(得分:1)

框架从语言上说:

  • 格式化日期通常是视图助手任务;

  • 如果您需要计算[例如一个列表的平均值],你应该定义你自己的集合模型,并为它提供你将在你的应用程序中使用的方法,因为你有可能在不同的控制器中使用它们,你不想要复制任何代码。