开发者

Combining multiple controllers on one page, without loading controllers from a controller

开发者 https://www.devze.com 2023-03-23 02:05 出处:网络
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.

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号