对于反射我一般是使用配置来实现优雅的重定向
使用如下:
$config = [
'sanger.soperator.register' => [
'controller' => '\app\dapi\controller\Register',
'action' => 'index',
]
];
$params = request()->param();
if (!isset($params['method']) || !empty($config[$params['method']])) {
$this->ajaxReturn('false', 'method is not existance');
}
$class_params = $config[$params['method']];
$function = $class_params['action'];
$class = new \ReflectionClass($class_params['controller']);
if ($class->hasMethod($function)) {
$class->newInstance()->$function();
}
这样就实现了调用app\dapi\controll\Register这个class下面的index方法了