我何时应该在MVC中使用多个控制器? [英] when should i use multiple controllers in mvc?

查看:158
本文介绍了我何时应该在MVC中使用多个控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候您可能想在mvc中使用多个控制器吗?

are there times you might want to use multiple controllers in mvc?

例如

/controllers/foo.php

/controllers/foo.php

/controllers/bar.php

/controllers/bar.php

/controllers/foo/baz1.php

/controllers/foo/baz1.php

/controllers/foo/baz2.php

/controllers/foo/baz2.php

/controllers/bar/baz1.php

/controllers/bar/baz1.php

/controllers/bar/baz2.php

/controllers/bar/baz2.php

有人可能会在我想做的时候给出一些例子,以及一些控制器名称的例子.

could someone give some examples WHEN i might want to do that and some example controller names.

我想到的一个情况可能是您拥有一个主站点(针对用户)和一个管理站点(针对客户).

one occasion i thought about might be when you got a main site (for users) and a admin site (for customers).

感谢所有反馈和建议

推荐答案

通常,控制器处理代表相应数据库表的模型.因此,如果您具有表用户和帖子,则您的应用程序将具有用户和帖子模型,因此控制器将具有用户和帖子模型.这是典型的RoR方式,已在许多PHP MVC框架中使用.该应用程序中的URL如下所示:

Usually controllers deal with models, which represent corresponding database tables. So if you have tables users and posts, your app will have models User and Post, and therefore controllers Users and Posts. That is typical RoR way, which used in many PHP MVC frameworks. URLs in such application looks as follow:

/controller/action/parameter1/parameter2/...
i.e.
/users/edit/1/
or
/posts/new/

动作对应于控制器类方法.实际上,我认为它在MVC架构中已成为事实上的标准,因为它看起来自然而合乎逻辑.

And actions corresponds to controller class methods. Actually I think it became de-facto standart in MVC architecture, becuase it looks natural and logical.

这篇关于我何时应该在MVC中使用多个控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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