CodeIgniter Forums
Splitting one controller into multiple files - 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 one controller into multiple files (/thread-15910.html)



Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]xzela[/eluser]
Is there a way to split a single controller into multiple files?

I would like to start splitting a particular controller I'm working with into smaller pieces because it's starting to become rather large.

Here is an example of what I would like to achieve:

I have two urls:
Code:
http://localhost/junk/foo/1

http://localhost/junk/bar/1

These urls relate to the same controller 'junk'. But what I would like to do is be able to split the controller into two files so that foo and bar are not in the same file.

Does anyone know if this is even possible? or, is this the wrong way to go about it and large controllers are normal?


Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]Mark Skilbeck[/eluser]
Most languages acheive this with 'namespaces', although I don't think it's implemented in PHP or CI yet.


Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]Xeoncross[/eluser]
ya, just do it.

We had a controller here recently that actually split into 4 other controllers to help speed up the system. Splitting up un-related functionality among controllers makes your system faster.

Take a blog
1) view controller
2) CRUD controller
3) Archive controller
4) etc...

You could put all that in one huge view - but then you would have a HUGE file to load on each request.


Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]xzela[/eluser]
But how do you do it within one url? How do you load the extra functions? Do you have any code examples?


Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]Xeoncross[/eluser]
Routing


Splitting one controller into multiple files - El Forum - 02-18-2009

[eluser]xzela[/eluser]
ah....

interesting... Cool, thanks for the help.