Caloy
Caloy

Reputation: 89

Codeigniter: call a controller from another codeigniter file

I have this two file path:

    1: /api/math/application/controllers/test.php 
    2: /learn/mathtek/application/controllers/Auth.php

I need to call the controller from path2(Auth) inside the controller of path1(test). Is this possible? if yes how?

Ive tried to used the redirect() function but didnt work. Also i tried this:

require_once('/learn/mathtek/application/controllers/Auth.php');
            $aObj = new a();  //create object 
            $aObj->custom_a(); //call function

but it still didnt work...help please ... newbie in codeigniter here

Upvotes: 3

Views: 837

Answers (2)

Caloy
Caloy

Reputation: 89

Thanks guys for the help. I ended up doing a direct post of the path using redirect function to make it work.

1: /api/math/application/controllers/test.php - codeigniter1
2: /learn/mathtek/application/controllers/Auth.php - codeigniter2

Examples: If i want to call path(2) from path(1).

redirect('http://localhost/learn/mathtek/auth/signin'); --'signin' is a function inside 'auth' controller

thats the code inside the 'test' controller. This works in codeigniter even if its from different path of controller.

However this doesnt work for UNITY(WEBGL). Thats why i ended doing an echo and returning it back.

Upvotes: 2

Ashish Raj
Ashish Raj

Reputation: 488

You can't call any other controller action/method for have output or return value in your controller action/method because it is out of rules of MVC.

But you can redirect from one controller action to another controller action and pass argument in another controller action like below:

redirect("CONTROLLER/ACTION/ARGUMENT1/ARGUMENT2");

Edit:

suppose you are in Test controller and in test_method() action of Test controller then you can put your business logic code in the method and got some output and now you want to call any other controller function(eg: Auth) for perform any other operation with that output then you can pass that output in a redirect function as below:

redirect("Auth/auth_method/ARGUMENT1/ARGUMENT2");

Upvotes: 1

Related Questions