Welcome Guest, Not a member yet? Register   Sign In
Reference to active controller?
#1

[eluser]Dauntless[/eluser]
Hi,

Is there a way to get a reference to the active controller ?

I'm using a custom library and from within that library, I would like to execute a method on the active controller. I know this is really ugly (OO-wise), but it really is the best way at this time.

I'm thinking of something like
Code:
$this->CI =& get_instance();
$this->CI->activeController->myMethod();
Is this possible ?
#2

[eluser]xwero[/eluser]
$this->CI->uri->rsegment(1) always gives you the controller.
#3

[eluser]Colin Williams[/eluser]
$this->CI is an instance of the active controller. Although, there is probably a better way to do whatever it is you are doing.
#4

[eluser]xwero[/eluser]
Colin $CI can be a class variable of his library, $this-> is not related to CI all the time Smile
#5

[eluser]Dready[/eluser]
Hello,

get_instance() returns the active controller.
#6

[eluser]Colin Williams[/eluser]
Quote:Colin $CI can be a class variable of his library, $this-> is not related to CI all the time

xwero, it is related to CI when you set it to the result of get_instance(). Did you miss the $this->CI =& get_instance() part of his thread? Come on now...
#7

[eluser]xwero[/eluser]
Code:
$this->CI =& get_instance();
$this->CI->myMethod();
Is all you have to do.
#8

[eluser]Dauntless[/eluser]
Alright Big Grin.

(Where can I find documentation for the CI core methods & functions (=developer doc ?) ?)

Thanks!
#9

[eluser]xwero[/eluser]
Most functions are documented if you want to dig deeper you are going to read the code yourself Smile
#10

[eluser]Dauntless[/eluser]
That kinda sucks ...

I wouldn't even know where to start looking for the location of the get_instance() function ...




Theme © iAndrew 2016 - Forum software by © MyBB