Welcome Guest, Not a member yet? Register   Sign In
Can I call a controller method from other controller?
#1

[eluser]plainas[/eluser]
Ok, this situation should not happen if I would would design my application properly. Back in early development of this app, I split a controller in two and now I need to access a controller method from another controller.
Is that possible?

can i do something like

Code:
class A extends Controller{
    
    function A (){
        parent::Controller();
        }
        
        funtion hello(){  echo "boo!";}
}

class B extends Controller{
    
    function B (){
        parent::Controller();
        }
        
        funtion hello(){  A::hello();}
}

?
#2

[eluser]Tanque[/eluser]
it's look possible, but I've never tried, so I can't tell you...
#3

[eluser]Sam Dark[/eluser]
Try HMVC Modular extensions or Wick.
#4

[eluser]wiredesignz[/eluser]
Static calls are possible between classes for sure, but be aware that you stay in object context of the first class even while you execute the method of the second class.
#5

[eluser]plainas[/eluser]
[quote author="wiredesignz" date="1220914584"]Static calls are possible between classes for sure, but be aware that you stay in object context of the first class even while you execute the method of the second class.[/quote]

I was asking about making a static call in a condeigniter controller context. Like, the classes are not defined in the same file and AFAIK only the one requested through the url is initialized.

So i get this error:

Code:
Fatal error: Class 'Query' not found in....

so, the question remains, is there any way I can access another controller objects?
#6

[eluser]wiredesignz[/eluser]
include APPPATH.'controllers/query.php'; will allow you to access the class. PHP4 at its finest.

But that is not an Object,
#7

[eluser]plainas[/eluser]
Thank you all.

I'll use this last solution.

A static call is ok in this case, no need to create any instance, just acessing a method.
#8

[eluser]jet_black82[/eluser]
why not put all the "shared methods" on a helper? like this you could access the methods for both controllers everywhere.

Chears




Theme © iAndrew 2016 - Forum software by © MyBB