3

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

7
  • 2
    Never include one controller to another. Commented Feb 10, 2016 at 7:16
  • 1
    Not possible to load another codeigniter file in one codeigniter file. Commented Feb 10, 2016 at 7:18
  • you can create one controller as a library or helper according to your requirement and call in another controller. Commented Feb 10, 2016 at 7:33
  • @wolfgang1983 do you have any sample for HMVC? Commented Feb 10, 2016 at 8:56
  • "stackoverflow.com/questions/6500022/…" You should refer this link Commented Feb 10, 2016 at 9:06

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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");

1 Comment

@Caloy: If you think it is the best solution for your problem then you can vote up my answer and mark as best solution... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.