我想获取方法名。例如,A url调用method1
,并拨打私人电话method2
,method2
想知道谁调用此方法。我怎么能这样做。codeigniter从父方法获取方法名
我可以使用__FUNCTION__
或$this->router->method
上method1
,并把它作为method2
参数。但是我想知道我可以在method2
上得到这个方法吗从method1
中调用?太感谢了。
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class ControllerName extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function method1()
{
$this->_method2()
}
private function _method2()
{
// How to get call method name method1,
// Don't use parameter
// $who_call_me = 'method1';
}
}
'$ callers'数组就像堆栈?例如'method1-> method2-> method3',数组应该是$ caller [1] ['function'] = method2,$ caller [2] ['function'] = method3 – lighter
是的。它创建一个数组。或者如果你只是想知道以前的方法调用,你可以使用array_shift。我会在我的答案中编辑。 – sunny
非常感谢! – lighter