diff --git a/App/Controllers/Home.php b/App/Controllers/Home.php index b02dbda..c670073 100644 --- a/App/Controllers/Home.php +++ b/App/Controllers/Home.php @@ -5,7 +5,6 @@ namespace App\Controllers; use Core\Model; use \Core\View; use App\Models; - /** * Home controller * @@ -34,4 +33,9 @@ class Home extends \Core\Controller public function renderAction() { } + public function docsAction(){ + $docs = new Models\Doc(); + //$this->JsonResp(200,$docs,"OK"); + } } + diff --git a/App/Models/Doc.php b/App/Models/Doc.php index 4cb76e7..5be490d 100644 --- a/App/Models/Doc.php +++ b/App/Models/Doc.php @@ -8,15 +8,19 @@ use PDO; class Doc extends Model { + public $tableName = 'doc'; + public function __construct() { + parent::__construct(); + } /** * Get all the users as an associative array * * @return array */ - public static function getAll() + public function getAll() { $db = static::getDB(); - $stmt = $db->query('SELECT * FROM users'); - return $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt = $db->query('SELECT * FROM doc'); + return $stmt->fectchAll; } } \ No newline at end of file diff --git a/App/Models/User.php b/App/Models/User.php index 25f57c4..7d403fd 100644 --- a/App/Models/User.php +++ b/App/Models/User.php @@ -11,7 +11,7 @@ use PDO; */ class User extends \Core\Model { - + /** * Get all the users as an associative array * @@ -20,6 +20,7 @@ class User extends \Core\Model public static function getAll() { $db = static::getDB(); $stmt = $db->query('SELECT * FROM users'); + return $stmt->fetchAll(PDO::FETCH_ASSOC); } public static function Insert($user){ @@ -44,4 +45,5 @@ class User extends \Core\Model ); return $stmt->fetchAll(PDO::FETCH_ASSOC); } + } diff --git a/Core/Model.php b/Core/Model.php index 4650c28..5d4f094 100644 --- a/Core/Model.php +++ b/Core/Model.php @@ -12,7 +12,28 @@ use App\Config; */ abstract class Model { + public $tableName; + public $columns = array(); + //获得一个表的所有列名 + function __construct(){ + $this->getColumns($this->tableName); + } + public function getColumns($tableName) { + $db = static::getDB(); + $sql = "show columns from ".$tableName; + $stmt = $db->query($sql); + $res = $stmt->fetchAll(); + if(static::getDB()!=null){ + try{ + foreach ($res as $key => $value){ + array_push($res,$value[0]); + } + }catch (\PDOException $e){ + echo $e->getMessage(); + } + } + } /** * Get the PDO database connection * @@ -40,7 +61,6 @@ abstract class Model // Throw an Exception when an error occurs $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } - return $db; } } diff --git a/public/index.php b/public/index.php index fcf90d6..aff510f 100644 --- a/public/index.php +++ b/public/index.php @@ -29,7 +29,6 @@ $router->add('', ['controller' => 'Home', 'action' => 'index']); $router->add('{controller}/{action}'); $router->AddPrefix(\App\Config::ROUTE_PREFIX); try{ - //echo $_SERVER['REQUEST_URI']; $router->dispatch($_SERVER['REQUEST_URI']); }catch (Exception $exception){ echo $exception;