蛋糕PHP架构

发布于 2024-11-30 05:22:18 字数 446 浏览 0 评论 0原文

我有一个关于 CakePHP 架构的问题。

我有一个应用程序,它只有两个模型(产品和类别)。

我必须制作一个在线产品浏览器。对我来说,拥有一个“产品”控制器和一个“类别”控制器是没有意义的,因为我将在产品上执行 20 多个操作,而在类别上没有任何操作。

我有几个关键功能,我可以为每一个功能配备一个控制器吗?例如,一个控制器“Search”,其操作为“SearchResult”、“AdvancedSearch”、“BasicSearch”。

我们将是这个项目的几位开发人员,我不希望我们总是被阻止,因为有人正在产品控制器上进行一些编辑(而且我真的不喜欢包含 1000 多行代码的文件)。

第二个问题:我应该使用什么机制将视图片段化到几个不同的子视图中? 例如,对于一个产品的详细信息的查看,我有很多东西要显示:图片部分,描述部分,类似产品,评论,...是否可以有子部分?

非常感谢

I've a question for CakePHP about its architecture.

I've an application, which will have only two models(products and categories).

I've to make an online product browser. For me it makes no sens to have one controller "Products" and one controller "Categories", because I will have 20+ actions on the Products and none on the Categories.

I've several key functionnalities, can I have one controller for each of those functionnalities? e.g. One Controller "Search", which have action "SearchResult", "AdvancedSearch", "BasicSearch".

We will be several developers on this project and I don't wish we are always all blocked because one is doing some edit on the product controller(and I really don't like file with 1000+ lines of code).

Second question: What is the mecanism I should use to fragment view in several different sub-view?
E.g. For the view of the details of one product, I've a lot of things to display: Pictures section, description section, similar products, review, ... Is it possible to have sub-part?

Thank you very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2024-12-07 05:22:18

对于“子视图”,请查看“元素”,它们就是这样。它们是可以包含在其他视图中的视图代码片段。元素的正确结构可以创建一些非常优雅的视图/子视图关系。
http://book.cakephp.org/view/1081/Elements

至于你的控制器问题,这也是我一直在努力解决的问题。从我看来,您似乎对自己的行为进行了错误分类。考虑您正在执行的操作的替代分类法(将所有搜索功能混合到一个控制器中就是一个很好的例子)。

也许您应该将控制器视为对各种操作进行分类的对象,而不是可以执行各种操作的站点的各个方面(就像您正在做的那样)。因此,您可能拥有的不是可以搜索、列出、购买等的 CATEGORY 控制器,而是产品控制器(它处理聚合(可能按类别)或单独查看您的产品),也许还有用户控制器对于您的用户帐户?如果不查看您的应用程序细节,很难说。搜索将成为在您的产品上执行的操作

我犯的错误之一是根据我将拥有的页面而不是模型来选择控制器。考虑您的数据(模型)以及可以对其执行的操作(控制器中的操作),然后考虑您的视图。

我希望能为您提供更具体的帮助,但在不了解您的应用程序的具体需求的情况下,我只能为您提供有关如何分解控制器的指南。看看这个问题:

CakePHP - 文件结构混乱- 不同的控制器,还是全部相同?

有关该主题的更多讨论。

希望有帮助!

For "sub-views" look into Elements, which are just that. They are snippets of view code that can be included in other views. The proper structuring of elements can create some very elegant view/subview relationships.
http://book.cakephp.org/view/1081/Elements

As for your controller issue, it's one I've grappled with as well. From what I see, it sounds like you're misclassifying your actions. Think about alternative taxonomies for the actions you're doing (mixing all the search functions together into a controller is a great example).

Perhaps you should think about controllers as objects that classify various actions rather than aspects of your site on which various actions can be performed (as it seems you're doing). So rather than a CATEGORY controller on which you can search, list, buy, etc., you might have, the product controller (which handles viewing your products either in an aggregate - perhaps by category - or individually), and perhaps a user controller for your users accounts? It's hard to say without looking at your application specifics. Search would then be an action that would be performed on your product.

One thing that I have made the mistake of doing is picking my controllers based on pages i'll have rather than on models. Think about your data (models) and the actions that can be performed on them (actions in the controller), THEN think about your views.

I wish I could give you more specific help, but without knowing your application's specific needs, I can only give you guidelines on how to break down your controllers. Take a look at this question:

CakePHP - file structure confusion - different controllers, or all in same?

for more discussion on the topic.

Hope that helps!

时光病人 2024-12-07 05:22:18

如果您没有与之关联的方法/操作,则不需要类别控制器。我假设您可能需要一个管理员 CRUD 来管理您的类别?

关于搜索;您的核心搜索功能应驻留在产品模型中,其中各种控制器调用适当的方法。在大多数情况下,一种型号的基本或高级搜索可以通过一种方法来处理,这只是更多搜索字段的问题吗?

如果您有多个开发人员并且担心同一文件上的冲突,您确实需要考虑版本控制,例如 GITSVN 而不是与 MVC 框架核心方法相反的方法。将来会给你带来很多麻烦。

我相信您关于“子视图”的问题可以通过使用 elements 来解决,这是有效的视图的可重用部分。

祝你好运

You don't need a Categories controller if you have no methods/actions associated with it. I assume you may want an admin CRUD for administrating your categories?

Regarding searching; your core search functions should reside in the Products model with the various controllers calling the appropriate methods. Basic or Advanced searching on one model in most cases can be handled by one method, its only a matter of more search fields surely?

If you have several developers and are worried about conflicts on the same file you really need to be considering version control like GIT or SVN rather than approaches contrary to a MVC frameworks core methodology. It will cause you a lot less problems in the future.

I believe you question regarding 'sub views' is solved by using elements, which is in effect reusable sections of views.

good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文