16

I have two applications developed in CodeIgniter, both are working on separate server, i.e.

www.CI_App_1.com

and

www.CI_App_2.com

Now I want to integrate CI_App_2 into CI_App_1 application, so after that I'm able to call default_controller of CI_App_2 from one of link from CI_App_1.

My folder structure :

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

I want to access CI_App_2 after user is logedin from CI_App_1. After authenticating process user is able access my CI_App_2 only, If user try to access it without authenticating, got an error message :

Access forbidden

I referred following links :

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

But in above links they said that it should be done using HMVC module structure, but not any one mention that both controller files are from same application or different. I want to access default_controller from second application into first application.

Is it possible ?

Any kind of help is appreciated. Thanks in advance. Hope you got my question.

Community
  • 1
  • 1
Ganesh Aher
  • 1,118
  • 3
  • 21
  • 51
  • 1
    I think the best is to restructure a little to have app_1 and app_2 at the same level (not nested) and create a new auth method for both – Vickel Feb 13 '17 at 01:16
  • Please give an example what you want to say. Because I tried to add default_controller from App2 to App1's Controller folder. And rewrite routes for them. But it did not work. – Ganesh Aher Feb 13 '17 at 05:17
  • Sounds like you want authentication across servers. [See this answer about a custom session handler.](http://stackoverflow.com/questions/16243450/share-a-session-across-multiple-servers-with-different-domains) – ourmandave Feb 17 '17 at 23:24

2 Answers2

4

Following function set on application_1 default_controller may be its work.

public function _remap($method) {
    $userdata = $this->session->userdata('user');
    if (!empty($userdata)) {
        modules::run('application_2/controller/default_controller');
    }
}
Renish Patel
  • 658
  • 1
  • 13
  • 14
2

Well, Its best that instead of merging these. you need to shift

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

In this way, you can access app2 inside the app1 with some addition of routes.

I must recommend that don't shift all code of app2 in app1 as it is.

It will not good.

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
  • But in that way it will allow direct access to URL of App2. Without authenticating using App1. Because if we add some routes them it will directly access that route/ url. – Ganesh Aher Feb 13 '17 at 05:13
  • Yes you are right. But using routes you can bypass app1's authentication or related bariers – Naveed Ramzan Feb 13 '17 at 05:29
  • Actually I want that authentication. I don't want to bypass them. Other wise by creating sub-domain it will work. But without App1 authentication I want allow user to access App2 directly. That is my actual problem and question. – Ganesh Aher Feb 13 '17 at 05:33
  • OK right, then you can group app2 and add an authentication for only those app2 routes. – Naveed Ramzan Feb 13 '17 at 05:39
  • I recommend to use same database for both apps once App 1 authentication is complete insert a entry in data base and check this entry in app 2 default controller if user valid the allow other router url to error page whatever you want to show. – Yaseen Ahmad Feb 13 '17 at 12:06