在一个页面上组合多个控制器,无需从一个控制器加载控制器
我正在尝试创建一个页面,根据用户权限显示某些小部件/包含内容。我对 CodeIgniter 和 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在寻找称为布局的东西。 Codeigniter 没有这样的现成功能,但布局基本上是在多个操作之间委派(前端控制器)请求。每个操作都独立工作,并分配有自己的视图。
然后布局会小心地将所有这些组合到一个输出中。
这种方法还需要注意的是,您不会从另一个控制器调用一个控制器,因此您可以将不属于彼此的代码分开,否则会因为同时执行太多操作而变得混乱。
您可能会对这个讨论感兴趣:Codeigniter 布局?,Codeigniter 常见问题解答 也有更多相关信息,更具体wiki 中每个页面上的页眉、页脚和菜单。
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.
在我看来,您正在寻找 CodeIgniter 的模块化扩展 。这允许您将应用程序分解为可以相互调用的模块。就您而言,您将有一个可以从其他模块调用的日历模块。
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.