Welcome Guest, Not a member yet? Register   Sign In
Identify calling method
#1

[eluser]richzilla[/eluser]
Hi all,

Im looking for a way of identifying the calling method in part of my code. Ive seen the method here to do it from the backtrace array, but i was wondering if there was a cleaner way to do it?

or alternatively if someone can tell me a better way of achieving this:

I want a method to behave differently if it was called through the normal MVC pattern - passing its data to a view and outputting, and if it was called 'internally' from another method in the same controller - returning the data to the calling method. Ive thought about an optional 'flag' in the method arguments set to false by default and overridden to true if called internally, but again im wondering if there is a cleaner way to do this?

Any help would be appreciated.
#2

[eluser]cahva[/eluser]
Hmm.. If you're calling that method from the same controller, just set a variable that its called internally?
Code:
class Foo extends Controller {

    var $internal = FALSE;
    
    function __construct()
    {
        parent::__construct();
    }
    
    function index()
    {
        $this->internal = TRUE;
        $this->bar();
    }

    function bar()
    {
        if (!$this->internal)
        {
            echo 'called from url foo/bar';
        }
        else
        {
            echo 'called internally';
        }
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB