dtrpv60860 2008-10-08 21:59
浏览 77

如何在MVC中确定我的控制器?

I'm fairly new to MVC coming from a php background where I designed by view and created pages when I needed something like say a login form. I'd have a file called login. This only sucked when I needed a new login form to login a different type of user. Say an admin. I'd then have to create a new page called login-admin.php or something of that nature.

Recently I began to explore MVC and particularly frameworks and the biggest problem I am having is determining how exactly you come up with your controllers. I've been told to either go the one controller per view file route, or get your controllers based upon your domain objects.

I understand I can have a user controller and a lot of methods to manipulate that object say user/add, user/edit, user/delete, user/profile. But in this instance it seems that once you need views that don't necessarily fit within a "domain object" that it's hard to decide where to stick them.

So, what is the best practice when determining what your controllers will be???

  • 写回答

4条回答 默认 最新

  • dongtuo3530 2008-10-08 22:09
    关注

    I use one controller per "area of concern".. That's sort of arbitrary, and generally is a slightly larger category, based in the domain model, that includes multiple objects.

    In other words, lets say in your domain model you have security as one of your areas of concern. It might involve many views, and many domain objects, but I would make it a single controller, which handled all security related actions.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?