修改调用方式

This commit is contained in:
TOP糯米 2019-06-10 15:43:15 +08:00
parent 6c54911825
commit 34d6a373a5
3 changed files with 9 additions and 6 deletions

View File

@ -6,6 +6,10 @@ use app\home\model\Job;
class Index extends Common { class Index extends Common {
public function _init() {
echo 1;
}
public function index() { public function index() {
$model = model(Job::class); $model = model(Job::class);
return [ return [

View File

@ -64,7 +64,7 @@ class Database {
$this->config = $config = Register::get('Config')->get('db'); $this->config = $config = Register::get('Config')->get('db');
$this->table = $config['prefix'] . $table; $this->table = $config['prefix'] . $table;
$this->pk = $pk; $this->pk = $pk;
$this->setDriver($driver, Register::get('Config')->get('db')); $this->setDriver($driver, $this->config);
} }
private function __clone() { private function __clone() {

View File

@ -122,14 +122,13 @@ class Router {
$this->beforeRoute(); $this->beforeRoute();
$object = new $this->class(); $object = new $this->class();
if (method_exists($object, '_init')) { $reflectionClass = new \ReflectionClass($this->class);
if ($reflectionClass->hasMethod('_init')) {
$data = $object->_init(); $data = $object->_init();
} }
if (!isset($data) || $data == null) { if (!isset($data) || $data == null) {
$data = call_user_func_array([ $reflectionMethod = new \ReflectionMethod($this->class, $this->action);
$object, $data = $reflectionMethod->invokeArgs($object, $this->param);
$this->action
], $this->param);
} }
$this->afterRoute($data); $this->afterRoute($data);