From 34d6a373a58b151b639dd1f41d833c55aff44946 Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Mon, 10 Jun 2019 15:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=83=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/home/controller/Index.php | 4 ++++ framework/library/Database.php | 2 +- framework/library/Router.php | 9 ++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/application/home/controller/Index.php b/application/home/controller/Index.php index 7679122..8caed59 100644 --- a/application/home/controller/Index.php +++ b/application/home/controller/Index.php @@ -6,6 +6,10 @@ use app\home\model\Job; class Index extends Common { + public function _init() { + echo 1; + } + public function index() { $model = model(Job::class); return [ diff --git a/framework/library/Database.php b/framework/library/Database.php index 4dc3faa..63b7a07 100644 --- a/framework/library/Database.php +++ b/framework/library/Database.php @@ -64,7 +64,7 @@ class Database { $this->config = $config = Register::get('Config')->get('db'); $this->table = $config['prefix'] . $table; $this->pk = $pk; - $this->setDriver($driver, Register::get('Config')->get('db')); + $this->setDriver($driver, $this->config); } private function __clone() { diff --git a/framework/library/Router.php b/framework/library/Router.php index 1de4a87..3282cf4 100644 --- a/framework/library/Router.php +++ b/framework/library/Router.php @@ -122,14 +122,13 @@ class Router { $this->beforeRoute(); $object = new $this->class(); - if (method_exists($object, '_init')) { + $reflectionClass = new \ReflectionClass($this->class); + if ($reflectionClass->hasMethod('_init')) { $data = $object->_init(); } if (!isset($data) || $data == null) { - $data = call_user_func_array([ - $object, - $this->action - ], $this->param); + $reflectionMethod = new \ReflectionMethod($this->class, $this->action); + $data = $reflectionMethod->invokeArgs($object, $this->param); } $this->afterRoute($data);