Welcome Guest, Not a member yet? Register   Sign In
where do "actions" go?
#4

(09-16-2015, 07:49 AM)mwhitney Wrote: Traditionally, the methods in controllers are referred to as actions, but, since we're calling controller methods based on the URL, and we might want an "action" to be available from multiple locations (and there are all sorts of issues with calling multiple controllers given the way CI treats the controller), a library is a good alternative.

However, if the "action" is really just something which is rooted in your business logic, there are very good arguments for keeping it in your model, or dividing your model into two models (the one with the business logic which you would load directly and the one with the lower-level database interaction which would be loaded by your business-logic-model).

When looking at most design patterns which define a model, the model is a much higher-level object than what we typically have in CodeIgniter. Part of this is simply because most design patterns come from other languages which often supply higher-level interfaces to the database as part of their standard libraries. So, the idea of building a model which performs basic CRUD operations exists, but isn't really widely used in those languages.

Further, no matter where you ultimately put the code, you don't want your business logic for a particular operation repeated or spread across multiple classes. So, in my opinion, you can create a library or a model to hold this code, but it just makes more sense to me, from the perspective of the controller, to load a model when I need to do something which ultimately results in a change to the database, than to load a library. I'm perfectly fine with the idea of separating business logic and CRUD, and having them both exist in models (or the business logic in a library and the CRUD in a model), but I would take great lengths to avoid (or even prevent) loading the CRUD model directly from the controller if this is the case.

Thanks both for your responses. ThanksĀ mwhitney for a very detailed response explaining your thought process, very helpful.

Thanks again
R
Reply


Messages In This Thread
where do "actions" go? - by rickoneeleven - 09-16-2015, 03:07 AM
RE: where do "actions" go? - by PaulD - 09-16-2015, 06:07 AM
RE: where do "actions" go? - by mwhitney - 09-16-2015, 07:49 AM
RE: where do "actions" go? - by rickoneeleven - 09-16-2015, 12:47 PM
RE: where do "actions" go? - by cartalot - 09-16-2015, 02:40 PM
RE: where do "actions" go? - by rickoneeleven - 09-23-2015, 04:41 AM
RE: where do "actions" go? - by ravinesh - 09-23-2015, 04:47 AM
RE: where do "actions" go? - by ComputingFroggy - 10-25-2015, 01:28 AM
RE: where do "actions" go? - by jaynarayan - 12-17-2015, 11:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB