开发者

codeiginter - business logic - controllers, models or library?

in CI, for me at least, views must开发者_高级运维 be your layout (html), controllers are the structure and models handles the data. When building an app, where do business logic will be?

I have maintained the controller only to handle urls, because i want to separate structure to business logic. i've been using my models to retrieve data and process it (data and business logic), but there would be a problem if i decided to switch data sources.

is it a best practice to always introduce a library to separate the main business logic?


Business logic should be in your models. Models need not necessarily have database connectivity embedded in their objects. Within the model tier, you may want to have some classes devoted solely to business logic and others devoted to operations such as database connectivity. Some frameworks, like Groovy on Grails, recommend using Services for business logic that is repeated across controllers (checking if user is authenticated)/model objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜