We are developing a module and the controller mcp file has become quite large. I wondered if there is a best practice for splitting this into multiple files. It's a collection of methods in the class our module_mcp class, so can these be split out into other files somehow? Multiple controllers instead of one? We could use the include() method in PHP but doesn't seem it would be the best practice to do this.
I would suggest a couple things to help separate our your code.
- As Derek mentioned in a comment above, make sure you're abstracting your data model work to a model class.
- You can also create a libraries directory within your add-on package and begin to create your own set of libraries. Since they are local to your package, you'll be able to easily load them like
$this->EE->load->library('your_module_class_name');Then, within the control panel file you can simply pass off processing to your library. As the code gets more complex, you can abstract into multiple libraries as needed.
Of course all of this is really a matter of your own personal taste and need for organization. You want to be careful not to abstract too much, making it incredibly difficult to trace through later.