CodeIgniter Forums

Full Version: Splitting one controller into multiple files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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:


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?

El Forum

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

El Forum

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.

El Forum

But how do you do it within one url? How do you load the extra functions? Do you have any code examples?

El Forum


El Forum


interesting... Cool, thanks for the help.