Welcome Guest, Not a member yet? Register   Sign In
Multiple controllers per page + Multiple instances of the same model
#16

Hi,

You have a table of users, and a table of user groups. If users can only be in one group, just add a column on the user table indicating which group they are in.

If a user can be in multiple groups, you need an additional table linking user_id to group_id, so a user can have multiple group affiliations.

As for the crud model idea, don't worry about it, I have just found it really helps speed up things. For instance, I add a table called 'Plants', and I can immediately read from, update to and delete from that table using my crud model, never having to write a single query, checking return values or writing if($query->num_rows() > 0) ever again! For more complex queries on the plants table, I can then make a plants model and put the query and logic in there. However it is amazing how much of the time my previous models were filled with the same repetitive code again and again.

As for thin controllers, and heavy libraries, it makes sense to me. So my controller says, who are they (auth library), what do they want to do (permissions library), did it work (another library), what do I display (theme library). My business logic is nicely seperated, each library is individually testable, my code is simple to read, it is very DRY, maintainable and easy to develop further. It is also easy then to port different libraries between sites. But the beauty of CI is you can it any way you want. When I first started out I had everything in my controllers including database calls.

Best wishes,

Paul.
Reply


Messages In This Thread
RE: Multiple controllers per page + Multiple instances of the same model - by PaulD - 07-23-2016, 09:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB