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 vue3项目部署之后报错
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥15 vba参数转c++ SAFEARRAY
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂
  • ¥20 判断两个表是否完全相同