public function processApi(){
$func = strtolower(trim(str_replace("/","",$_SERVER['REQUEST_URI']))); //echo $func;
if((int)method_exists($this,$func) > 0)
$this->$func();
else
$this->response('',404);
echo '404'; // If the method not exist with in this class, response would be "Page not found".
}
答案 0 :(得分:0)
您应该使用此代码
public function processApi(){
$func = strtolower(trim(str_replace("/","",$_SERVER['REQUEST_URI'])));
if(method_exists(get_called_class(), $func))
{
$this->$func();
}else{
$this->response('method not exists',404);
}
}
此方法获取类名
get_called_class()
在方法中设置类名返回true是否存在false方法
method_exists(get_called_class(),$ func)
试试这段代码