【问题标题】:Integrating/ Migrating two CodeIgniter applications.集成/迁移两个 CodeIgniter 应用程序。
【发布时间】:2017-06-27 07:15:26
【问题描述】:

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

www.CI_App_1.com

www.CI_App_2.com

现在我想将CI_App_2 集成到CI_App_1 应用程序中,所以之后我可以从CI_App_1 的链接之一调用default_controllerCI_App_2

我的文件夹结构:

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_1 登录后访问 CI_App_2。验证过程后,用户只能访问我的CI_App_2,如果用户尝试在没有验证的情况下访问它,则会收到错误消息:

禁止访问

我参考了以下链接:

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 模块结构来完成,但没有人提到两个控制器文件来自相同的应用程序或不同的应用程序。我想从第二个应用程序访问default_controller 到第一个应用程序。

有可能吗?

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

【问题讨论】:

  • 我认为最好的办法是稍微重组一下,让 app_1 和 app_2 处于同一级别(不嵌套),并为两者创建一个新的身份验证方法
  • 请举例说明你想说什么。因为我试图将 App2 中的 default_controller 添加到 App1 的 Controller 文件夹中。并为他们重写路线。但它没有用。
  • 听起来您想要跨服务器进行身份验证。 See this answer about a custom session handler.

标签: php .htaccess codeigniter url-routing


【解决方案1】:

application_1 default_controller 上设置的以下功能可能是它的工作。

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

【讨论】:

    【解决方案2】:

    嗯,最好不要合并这些。你需要换班

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

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

    我必须建议不要将 app2 的所有代码按原样转移到 app1 中。

    不会好的。

    【讨论】:

    • 但是这样就可以直接访问 App2 的 URL。无需使用 App1 进行身份验证。因为如果我们添加一些路由,它们将直接访问该路由/ url。
    • 是的,你是对的。但是使用路由可以绕过 app1 的身份验证或相关障碍
    • 其实我想要那个身份验证。我不想绕过他们。否则,通过创建子域它将起作用。但如果没有 App1 身份验证,我希望允许用户直接访问 App2。这是我的实际问题。
    • 好的,那么您可以对app2进行分组并仅为那些app2路由添加身份验证。
    • 我建议在 App 1 身份验证完成后对两个应用程序使用相同的数据库在数据库中插入一个条目,如果用户有效,则在应用程序 2 默认控制器中检查此条目允许其他路由器 url 到错误页面无论如何你想展示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多