Welcome Guest, Not a member yet? Register   Sign In
Giant controllers

Hey all. CI3. My controllers are getting way too big. One of them is 3500 lines of code and displays 70 pages.

Was wondering what the best way to refactor this is. Should I break every page out into its own controller? That might work... then I could easily add private methods supporting that page. I'd also like any refactorings to be unit test-friendly, going to start adding unit tests to this legacy codebase.

Any other ideas? Thanks in advance for feedback.

(This post was last modified: 06-22-2022, 06:36 AM by ikesela.)

it better to organizes pages into controller. more controller is better but not too many controller. categorized it

Well, if you have so many pages, it might be normal.

For my cms projects I personally divide them first in two as Site and Admin folders and then in these folders, for example in Admin one, I have seperate files for products or sliders etc but not for every single page.

Plus, you can use Libraries or helpers for some repeating things

(This post was last modified: 06-22-2022, 11:14 AM by TheAdmiral.)

Yeah I have mine roughly divided into Admin, Public, and ControlPanel controllers. The ControlPanel controller is the one that is too big as described above. I thought that it made the most sense to group by the permissions needed (so they could share a private permissions check method), but ControlPanel is too big now, it's a code smell.

Theme © iAndrew 2016 - Forum software by © MyBB