This article mainly shares with you how the CI framework obtains the controller name and method name. There are three methods in total. I hope it can help you.
The first method:
Even if there are __CLASS__, __FUNCTION__ magic variables, but in the parent class controller, or In the model, only the class name and method name of the current class can be obtained.
Second method:
##$this- >uri->segment(3,0);
This is obtained through the URL. In case the url route is customized, this method is not very elegant.
##The third method: (Perfect)
$con = $this->router->fetch_class();//获取控制器名 $func = $this->router->fetch_method();//获取方法名
Related Recommended:
The above is the detailed content of How does the CI framework obtain the controller name and method name?. For more information, please follow other related articles on the PHP Chinese website!