dongshuohuan5291 2016-09-17 19:53
浏览 38
已采纳

Mvc模式:我应该在哪里放置这个PHP代码?

I'm developing a php application and enforcing a strict mvc pattern whenever possible. I have a view,the header of the page, which should change the background image depending on the current month. Where should I place the php logic to decide which image to use as the Background? Inside the view file or on the caller (The parent file which includes the view)? If I put the code in the caller then I have to replicate the logic for each page (Every page has the same header view). I could put the logic inside the view, avoiding code duplication, but should a view supposed to have only view code? (no business logic)?

  • 写回答

1条回答 默认 最新

  • duanchi0897 2016-09-18 10:23
    关注

    keep in mind that view is not a template for the application. View is that piece of code that has the responsibility for the UI. So the logic for the background definitely belongs to the view. Also at classical MVC you have 1view 1controller ratio (UserView-UserController etc)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探