Welcome Guest, Not a member yet? Register   Sign In
load a controller inside a controller
#1

[eluser]Unknown[/eluser]
Hi there,

I really enjoy CI, and the controller/view thing.

I'm using CI since just a few days, and I have a simple question.

I have a controller for an index page, which calls the header view, the sidebar view, the index view, and the footer view.

I must include much code inside the sidebar (you know, login stuff, etc) and this code has to be available from the whole site, not just from the index page.

How can I do this? I initially thought about making a controller for the sidebar view, and then calling the controller inside the index controller, but maybe this isn't the best idea. However I don't know how to do this.

How can I solve this?

Thank you!
Matteo.
#2

[eluser]Colin Williams[/eluser]
Seriously, someone needs to write a song about this issue.

You have a ton of options:

1. Employ a template library, or something similar, to give you flexibility with views
2. Extend/replace the Controller class, and do your "global" operations there.
3. Use something like Wick or Modular Extensions (search the Wiki) to call other controller methods directly.

And those are just the 3 least-creative ways to go about it.
#3

[eluser]Colin Williams[/eluser]
Ah, but I see you're new here. Welcome to CI! If you search your issue, you should find a bizillion threads on the subject. Try a search for "MY_Controller"
#4

[eluser]Unknown[/eluser]
thank you! I've searched the forum before, but I didn't find anything, maybe because I was using the wrong keywords...!

thank you again!
#5

[eluser]Pascal Kriete[/eluser]
A quick search for "header footer" returned a bunch, here are two that might help: One and two.

Welcome to CodeIgniter.




Theme © iAndrew 2016 - Forum software by © MyBB