CodeIgniter Forums
splitting a big controller source file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: splitting a big controller source file (/thread-37301.html)



splitting a big controller source file - El Forum - 01-05-2011

[eluser]Bad Penguin[/eluser]
My controller has many methods because i dynamically get it called for almost any URL
and this controller have to detect the URL and display different kinds of data.

The controller source code is very big... 3.000 lines.

Any idea how to split it in different sources?

Or any way to call other controllers without doing HTTP redirects?


splitting a big controller source file - El Forum - 01-05-2011

[eluser]Cristian Gilè[/eluser]
Hi Bad Penguin,

you can't call other controller method without redirect but you can:

- use a base controller (MY_Controller) and extends your big controller
- use a library
- use HMVC (https://bitbucket.org/wanwizard/modular-ci/src)


splitting a big controller source file - El Forum - 01-05-2011

[eluser]Unknown[/eluser]
I have same scenario in my codeigniter application which also has big controller size. I want to split this controller into manageable modules. And my application is hosted on php 4 server and i can't use modular extension (HMVC), because it runs on PHP5 server.

Then is there any other way to split my bigger source code controller into smaller ones. Please help me in this issue.

Thank you,
Shah Nawaz


splitting a big controller source file - El Forum - 01-05-2011

[eluser]smilie[/eluser]
Shah, as Cristian already mentioned look into libraries to see if there is anything you could split to libraries (or helpers).

Cheers,
Smilie


splitting a big controller source file - El Forum - 01-05-2011

[eluser]gyo[/eluser]
Just guessing... would URI Routing help?


splitting a big controller source file - El Forum - 01-05-2011

[eluser]Bad Penguin[/eluser]
[quote author="gyo / suashi" date="1294263241"]Just guessing... would URI Routing help?[/quote]

No, obiovusly the controller is big because it need to handle first part of the url (usually the class) in a way to detect wich content need to be displaed (out of 20 different models) ... and... $route['static_text'] is not my way too because static_text need to be in MANY languages Smile


splitting a big controller source file - El Forum - 01-05-2011

[eluser]Bad Penguin[/eluser]
[quote author="Cristian Gilè" date="1294248477"]
- use a library
[/quote]

Probably the best thing is to use a library and call:
static_method($this);

from within the controller?