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.
精彩评论