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

查看:97
本文介绍了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方法(此时与阵列(静态=>假)参数),例如,作为效应初探对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.

什么是从其他控制器的pre-负载数据的最佳方式在主控制器?

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.

下面是一个伟大的阅读由菲尔鲟鱼以及如何基类来实现它们。

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

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

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