메서드 이름을 원합니다. 예를 들어, A url이 method1
으로 전화를 걸어 method2
으로 전화하면 method2
은 누가이 방법을 호출하는지 알고 싶어합니다. 내가 어떻게 할 수 있니?codeigniter 부모 메서드에서 메서드 이름을 얻습니다.
나는 method1
에서 __FUNCTION__
또는 $this->router->method
을 사용할 수 있으며 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' 일 경우, array는 $ caller [1] [ 'function'] = method2, $ caller [2] [ 'function'] = method3이어야합니다. – lighter
yes. 그것은 배열을 만든다. 또는 이전 메서드 호출을 알고 싶다면 array_shift를 사용할 수 있습니다. 나는 내 대답을 편집 할 것이다. – sunny
감사합니다. – lighter