views:

49

answers:

2

I've starting using Codeigniter for a project recently (few months ago) but its getting a little out of hand with a bunch of models that need to interact with each other and I was wondering if I should be creating a library instead?

In my case, I have a user action that happens when you win a game and it would get logged in my user_model but I also want it to get put in my events_model?

Should something like this that affects multiple models become a library?

I know it should NOT be in the controller because I'd have to reuse this trigger in multiple controllers (might not make sense for the provided example but does for my application).

+1  A: 

You could leave your models modularised as they are and write your logic in libraries, this way you can access mutilple models though a single function in a library, without making your controllers untidy by loading multiple models and having none-interface orientated logic mingled in with interface logic.

DRL
+2  A: 

Libraries are meant to provide reusable functionality for your application, while models in the MVC architecture represent the actual data that your application deals with.

So to answer your question, you can implement a library that handles updating of multiple models. Just ensure that things like database inserts are handled by your models.

BoltClock