-
-
Save anonymous/9069b80459332ae30ff9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "core/controller.php"; | |
require_once "core/model.php"; | |
require_once "core/view.php"; | |
require_once "core/route.php"; | |
Route::start(); | |
class DBConnect | |
{ | |
const DB_NAME = "base.db"; | |
private $db; | |
static private $_instance = null; | |
private function __construct(){ | |
if(!(file_exists(self::DB_NAME))){ | |
$this->db = new PDO("sqlite " . sellf::DB_NAME); | |
$sql = "CREATE TABLE user | |
( | |
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | |
username VARCHAR(128) NOT NULL, | |
password VARCHAR(128) NOT NULL | |
); | |
CREATE TABLE post | |
( | |
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | |
title VARCHAR(128) NOT NULL, | |
content TEXT NOT NULL, | |
create_time INTEGER, | |
author INTEGER NOT NULL | |
); | |
CREATE TABLE comment | |
( | |
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | |
content TEXT NOT NULL, | |
create_time INTEGER, | |
author VARCHAR(128) NOT NULL, | |
email VARCHAR(128) NOT NULL | |
);"; | |
$this->db->exec($sql); | |
} else { | |
$this->db = new PDO("sqlite " . sellf::DB_NAME); | |
} | |
} | |
static function getInstance(){ | |
if(self::$_instance == null){ | |
self::$_instance = new DBConnect(); | |
} | |
return self::$_instance; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set("display_errors", 1); | |
require_once "application/config.php"; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Route | |
{ | |
static function start(){ | |
$controllerName = "Main"; | |
$actionName = "index"; | |
$routes = explode("/", $_SERVER['REQUEST_URI']); | |
if(!empty($routes[1])){ | |
$controllerName = $routes[1]; | |
} | |
if(!empty($route[2])){ | |
$actionName = $route[2]; | |
} | |
$modelName = $controllerName; | |
$controllerName = $controllerName . "Controller"; | |
$actionName = "action" . $actionName; | |
$modelFile = $modelName . ".php"; | |
$modelPath = "application/models/" . $modelFile; | |
if(file_exists($modelPath)){ | |
include $modelPath; | |
} | |
$controllerFile = $controllerName . ".php"; | |
$controllerPath = "application/controllers/" . $controllerFile; | |
if(file_exists($controllerPath)){ | |
include $controllerPath; | |
} else { | |
Route::error404(); | |
} | |
$controller = new $controllerName; | |
$action = $actionName; | |
if(method_exists($controller, $action)){ | |
$controller->$action(); | |
} else { | |
Route::error404(); | |
} | |
} | |
static function error404(){ | |
{ | |
$host = 'http://'.$_SERVER['HTTP_HOST'].'/'; | |
header('HTTP/1.1 404 Not Found'); | |
header("Status: 404 Not Found"); | |
header('Location:'.$host.'404'); | |
} | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="css/style.css"> | |
</head> | |
<body> | |
<?php include "application/views/" .$contentView; ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class View | |
{ | |
function generate($contentView, $date=null){ | |
if(is_array($date)){ | |
extract($date); | |
} | |
include "application/views/templateView.php"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment