CodeIgniter:在一次调用中调用多个控制器 [英] CodeIgniter: invoking multiple controllers in one call

查看:25
本文介绍了CodeIgniter:在一次调用中调用多个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决 CI 中的一种架构问题.我需要能够在主控制器中实例化其他控制器及其方法.例如

I am solving a kind of architectural problem inside CI. I need to be able to instantiate other controllers and their methods in main controller. E.g.

*main.php/function index():*
$controller2 = new Controller2();
$data['pre_loaded_data'] = $controller2 ->ajax_get_some_view(array('static'=>true));

这种方法背后的目标是构建加载一些屏幕部分的ajax应用程序在第一次加载时静态地,作为主 html 页面的一部分,但后来这些部分使用 ajax 方法更新为来自各种其他控制器(此时使用 array('static'=>false) 参数),例如作为对 onclick 事件的响应主页.

The goal behind this approach is to build ajax application which loads some screen parts statically at first load, as part of main html page, but later these parts are updated with ajax methods to from various other controllers(at this time with array('static'=>false) param), e.g as reponse to onclick event on main page.

问题在于 CI 的设计似乎并不支持多个控制器,并且会引发各种与加载器相关的错误,报告某些类即使在加载时也未加载.

The problem is that CI doens't seem to be design to support multiple controllers and throws various loader-related errors reporting that some class is not loaded even when it's loaded.

在主控制器中从其他控制器预加载数据的最佳方法是什么?

What would be the best approach to pre-load data from other controllers in the main controller?

推荐答案

您可能希望创建控制器将继承的基类.您还可以考虑通过使用 模块化扩展 来尝试使用 HMVC.

You might want to make base classes that controllers will inherit. You can also consider trying with HMVC by using Modular Extensions.

这是一篇精彩阅读关于 Phil Sturgeon 的基类以及如何实现它们.

Here's a great read on base classes by Phil Sturgeon and how to implement them.

这篇关于CodeIgniter:在一次调用中调用多个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆