3

I'm trying to create a page that displays certain widgets/includes dependent on the users permissions. I'm quite new to CodeIgniter and MVC.

Example. I have a calendar. This has a controller, model and view and it needs to be included on other pages. I want this calendar and a number of other similar 'widgets' to be displayed on one page. This page currently has a controller and view.

I know I shouldn't be loading a controller from another controller, but can't see a way round it. Can you load multiple controllers from a helper, or do I need some form of template?

Thanks,

Jacqui

JPickup
  • 388
  • 3
  • 17

2 Answers2

2

It sounds to me like you are looking for Modular Extensions for CodeIgniter. This allows you to break an application into modules that can be called from one another. In your case, you would have a calendar module which you could call from your other modules.

Chris Schmitz
  • 8,097
  • 6
  • 31
  • 41
  • if i was to use this modular approach, would i need to make everything modular. include for example logins? – JPickup Jul 28 '11 at 09:55
  • for anyone looking into using modules net tuts have a good tutorial [tutorial](http://net.tutsplus.com/tutorials/php/hvmc-an-introduction-and-application/) – JPickup Jul 28 '11 at 09:56
  • @JPickup No, you wouldn't need to make everything modular. You can still put controllers, models and views in the original CI directories. – Chris Schmitz Jul 28 '11 at 13:36
1

What you might be looking for is something called Layouts. Codeigniter does not have such a feature out of the box but layouts are basically delegating a (front-controller) request across multiple actions. Each action works on it's own and has it's own view assigned.

The layout will take care to put this all together into one output then.

This methodology takes care as well that you don't call one controller from another controller so you keep code apart that does not belong to each other or would get messed up because it does too much at once.

This discussion might be interesting for you: Codeigniter layouts?, the Codeigniter FAQ has more about it as well and more specifically Header and footer and menu on every page in the wiki.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • JPickup, that depends on your needs. I would look for something that is actually running the controlers (the template library does not), check this one: http://codeigniter.com/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/ or looking into hooks http://codeigniter.com/wiki/Chuck_Son%27s_take/ - the forum discussions shows a lot of different concepts, read first to make a better decision for your own problem. – hakre Jul 27 '11 at 15:39
  • @JPickup: Yes, read the forum discussion, just edited my last comment as well. When you made a decision write a bit about it so you can share your experience with others. – hakre Jul 27 '11 at 15:42