Welcome Guest, Not a member yet? Register   Sign In
Controller / View Relationship
#1

1 to 1 or 1 to many, is the question in short.

I'm coming from an ASP.NET C# Web Forms environment where forms/pages that are related to a business function are kept in the same folder. Web Forms has good security based on folders and only allowing users belonging to the permitted roles to access the pages in that folder. Much of the code is held in classes so the code behind the forms themselves can be quite light. We end up a structure that like:

example.com/ (public interface and many, many pages)
example.com/accounts (Accounts Department 'home' page and menu, accessed by Accounts and Managers)
example.com/accounts/customerlist
example.com/accounts/customeredit
... plus 100 more.
example.com/manager (Managerial section 'home' page, only Managers allowed)
example.com/manager/stafflist
example.com/manager/rosters
... plus another 50 more.
etc, etc.

For my CodeIgniter project, I'd assumed that I would have one controller per functional area (accounts, manager, etc), each with their many views. Each function within the controller would load the model for it's view. As with our ASP.NET folders, only users in the permitted roles would be able to access the views controlled by this controller and that it would pretty much mirror the above from the user's point of view. I want to leave aside the advanced opportunities presented by routing at this stage. The users are happy with the structure above.

My concern is that my controllers may get too big. For example, the 'accounts' role needs to access around 100 different views. They need to be able to access and update information on customer, invoices, suppliers, inventory and many, many more. The other few roles have fewer forms, but the same concept.

However, if you go for a 1 to 1 relationship between controller and view, it seems a bit of an abstraction to me. You might as well just have the model code in classes and mix what happens in the controller in with the HTML in a plain old PHP page. Which is what happens now in the Webforms system.

Is it best practice to have one controller per role and allow it to manage dozens of views or should I go the Apple way and have one controller for every view. Something in between maybe?

Thanks for any opinions.
Simon
Reply


Messages In This Thread
Controller / View Relationship - by simon - 04-28-2017, 03:59 AM
RE: Controller / View Relationship - by simon - 04-28-2017, 01:55 PM
RE: Controller / View Relationship - by InsiteFX - 04-28-2017, 07:56 AM
RE: Controller / View Relationship - by simon - 04-28-2017, 02:08 PM
RE: Controller / View Relationship - by PaulD - 04-29-2017, 03:29 AM
RE: Controller / View Relationship - by InsiteFX - 04-29-2017, 04:28 AM
RE: Controller / View Relationship - by simon - 04-29-2017, 02:19 PM
RE: Controller / View Relationship - by lillian - 05-11-2017, 01:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB