简体   繁体   English

CakePHP业务逻辑层

[英]CakePHP business logic layer

CakePHP doesn't seem to ever mention separating the business logic and data access layers of an app. CakePHP似乎没有提到将应用程序的业务逻辑和数据访问层分开。 This is my first MVC app and my "fat models" are turning out to be very fat because they contain all kinds of business logic whose only real thing in common is requiring access to the same database. 这是我的第一个MVC应用程序,我的“胖模型”变得非常胖,因为它们包含各种业务逻辑,其唯一的共同点是需要访问同一个数据库。

When you hear the suggestion to move your business logic from controllers into the model, is it really acceptable to wind up in such a state? 当您听到将业务逻辑从控制器转移到模型中的建议时,最终是否可以接受这种状态? Does CakePHP provide any structure for a separate business logic layer as part of their framework? CakePHP是否为单独的业务逻辑层提供任何结构作为其框架的一部分?

Thanks, Brian 谢谢,Brian

No. It sounds to me that what you are running into is the classic downside of the Active Record pattern. 不,对我来说,你遇到的是Active Record模式的经典缺点。 Also, it doesn't help that CakePHP is all based around result associative arrays instead of object instances. 此外,CakePHP全部基于结果关联数组而不是对象实例,这没有任何帮助。 I suggest that you take a look at packages like Doctrine 2 . 我建议你看看像Doctrine 2这样的软件包。 It implements a DataMapper pattern instead of an ActiveRecord pattern. 它实现了DataMapper模式而不是ActiveRecord模式。 It keeps your business logic completely separate from your data access layer. 它使您的业务逻辑与数据访问层完全分离。

There are CakePHP extensions to integrate Doctrine into CakePHP. 有CakePHP扩展可以将Doctrine集成到CakePHP中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM