mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进控制器的空操作方法调用 改进Rest控制器的_empty方法
This commit is contained in:
@@ -337,9 +337,10 @@ class App
|
|||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
// 操作不存在
|
// 操作不存在
|
||||||
if (method_exists($instance, '_empty')) {
|
if (method_exists($instance, '_empty')) {
|
||||||
$method = new \ReflectionMethod($instance, '_empty');
|
$reflect = new \ReflectionMethod($instance, '_empty');
|
||||||
$data = $method->invokeArgs($instance, [$action, '']);
|
$args = self::bindParams($reflect, Request::instance()->param());
|
||||||
self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
|
$data = $reflect->invokeArgs($instance, [$action, $args]);
|
||||||
|
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace think\controller;
|
namespace think\controller;
|
||||||
|
|
||||||
use think\Response;
|
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
use think\Response;
|
||||||
|
|
||||||
abstract class Rest
|
abstract class Rest
|
||||||
{
|
{
|
||||||
@@ -38,7 +38,7 @@ abstract class Rest
|
|||||||
{
|
{
|
||||||
// 资源类型检测
|
// 资源类型检测
|
||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
$ext = $request->ext();
|
$ext = $request->ext();
|
||||||
if ('' == $ext) {
|
if ('' == $ext) {
|
||||||
// 自动检测资源类型
|
// 自动检测资源类型
|
||||||
$this->type = $request->type();
|
$this->type = $request->type();
|
||||||
@@ -76,7 +76,7 @@ abstract class Rest
|
|||||||
$fun = $method . '_' . $this->method;
|
$fun = $method . '_' . $this->method;
|
||||||
}
|
}
|
||||||
if (isset($fun)) {
|
if (isset($fun)) {
|
||||||
return $this->$fun();
|
return call_user_func_array([$this, $fun], $args);
|
||||||
} else {
|
} else {
|
||||||
// 抛出异常
|
// 抛出异常
|
||||||
throw new \Exception('error action :' . $method);
|
throw new \Exception('error action :' . $method);
|
||||||
|
|||||||
Reference in New Issue
Block a user