集成/迁移两个CodeIgniter应用程序。

时间:2017-02-09 10:20:43

标签: php .htaccess codeigniter url-routing

我在CodeIgniter中开发了两个应用程序,两个都在单独的服务器上工作,即

  

www.CI_App_1.com

  

www.CI_App_2.com

现在我想将CI_App_2集成到CI_App_1应用中,之后我就可以从{{1}的一个链接中调用default_controller CI_App_2 }。

我的文件夹结构:

CI_App_1

我希望在用户从htdocs : -application_1 -application -application_2 -application -config -autoload.php -config.php -routes.php -controllers -app_2_controller.php -helpers -libraries -models -app_2_model.php -views -app_2_view.php -system -.htaccess -index.php -config -autoload.php -config.php -routes.php -controllers -app_1_controller.php -helpers -libraries -models -app_1_model.php -views -app_1_view.php -system -.htaccess -index.php 加入后访问CI_App_2。验证过程后,用户只能访问我的CI_App_1,如果用户尝试访问它而不进行身份验证,则会收到错误消息:

  

禁止访问

我参考了以下链接:

Call Controller method of CodeIgniter outside Application directory

CodeIgniter: Load controller within controller

How to load a controller from another controller in codeigniter?

Codeigniter : calling a method of one controller from other

http://www.techsirius.com/2013/01/load-controller-within-another.html

https://www.quora.com/Can-I-call-a-controller-function-that-resides-in-another-controller-in-CodeIgniter

http://www.devnetwork.net/viewtopic.php?f=72&t=131353

how to set up two codeigniter applications running on same server

https://www.codeigniter.com/user_guide/general/managing_apps.html

但是在上面的链接中他们说它应该使用HMVC模块结构来完成,但没有提到两个控制器文件来自同一个应用程序或不同。我想从第二个应用程序访问CI_App_2到第一个应用程序。

有可能吗?

感谢任何形式的帮助。提前致谢。希望你能得到我的问题。

2 个答案:

答案 0 :(得分:4)

在application_1上设置了以下函数,default_controller可能是它的工作。

public function _remap($method) {
    $userdata = $this->session->userdata('user');
    if (!empty($userdata)) {
        modules::run('application_2/controller/default_controller');
    }
}

答案 1 :(得分:2)

嗯,最好不要合并这些。你需要转移

app2/controllers  => app1/controllers/app2
app2/views  => app1/views/app2

通过这种方式,您可以通过添加一些路径来访问app1内的app2。

我必须建议不要在app1中移动app2的所有代码。

不会好。