From 796155efedd323baa0dc0014581ef873bece0f46 Mon Sep 17 00:00:00 2001 From: LeonardoBizzoni Date: Mon, 18 Apr 2022 15:53:59 +0200 Subject: [PATCH] Setup pagina vtuber --- www/Migrations/m_1650287984_vtuberTable.php | 25 ++++++++++++++ www/controllers/SiteController.php | 21 +++++++----- www/core/BaseModel.php | 1 + www/models/Vtubers.php | 37 +++++++++++++++++++++ www/pub/index.php | 4 +-- www/views/layouts/main.php | 2 +- www/views/live.php | 8 +++++ 7 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 www/Migrations/m_1650287984_vtuberTable.php create mode 100644 www/models/Vtubers.php create mode 100644 www/views/live.php diff --git a/www/Migrations/m_1650287984_vtuberTable.php b/www/Migrations/m_1650287984_vtuberTable.php new file mode 100644 index 0000000..899bca9 --- /dev/null +++ b/www/Migrations/m_1650287984_vtuberTable.php @@ -0,0 +1,25 @@ +db; + $sql = "CREATE TABLE vtubers ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(255) NOT NULL, + link VARCHAR(512) NOT NULL + ) ENGINE=INNODB;"; + $db->pdo->exec($sql); + } + + public function down() + { + $db = Application::$app->db; + $sql = "DROP TABLE vtuber"; + $db->pdo->exec($sql); + } +} +?> diff --git a/www/controllers/SiteController.php b/www/controllers/SiteController.php index 913bf56..432a4f0 100644 --- a/www/controllers/SiteController.php +++ b/www/controllers/SiteController.php @@ -3,6 +3,7 @@ namespace app\controllers; use app\core\BaseController; use app\core\Request; +use app\models\Vtubers; class SiteController extends BaseController { public function home() { @@ -13,16 +14,18 @@ class SiteController extends BaseController { return $this->render("home", $params); } - public function contact() { - return $this->render("contact"); - } - - public function handleContact(Request $req) { - $body = $req->getBody(); + public function live(Request $req) { + $errors = []; + $vtuberModel = new Vtubers; - # $body validation + if ($req->getMethod() == "post") { + $vtuberModel->loadData($req->getBody()); + $vtuberModel->getVtuberName(); - return "Handling submitted data"; + if ($vtuberModel->validate() && $vtuberModel->register()) { + return "Success"; + } + } + return $this->render("live", [ "model" => $vtuberModel ]); } } -?> diff --git a/www/core/BaseModel.php b/www/core/BaseModel.php index 9960ffe..0a6e6d8 100644 --- a/www/core/BaseModel.php +++ b/www/core/BaseModel.php @@ -63,6 +63,7 @@ abstract class BaseModel { } } + echo " "; return empty($this->errors); } diff --git a/www/models/Vtubers.php b/www/models/Vtubers.php new file mode 100644 index 0000000..894f66d --- /dev/null +++ b/www/models/Vtubers.php @@ -0,0 +1,37 @@ +save(); + } + + public function rules(): array + { + return [ + "username" => [self::RULE_REQUIRED], + "link" => [self::RULE_REQUIRED, [self::RULE_UNIQUE, "class" => self::class ]], + ]; + } + + public function getVtuberName() { + $this->username = "i got you bro"; + } +} diff --git a/www/pub/index.php b/www/pub/index.php index 57aa14d..a877dce 100644 --- a/www/pub/index.php +++ b/www/pub/index.php @@ -19,8 +19,8 @@ $app = new Application(dirname(__DIR__), $config); $app->router->get("/", [SiteController::class, "home"]); -$app->router->get("/contact", [SiteController::class, "contact"]); -$app->router->post("/contact", [SiteController::class, "handleContact"]); +$app->router->get("/live", [SiteController::class, "live"]); +$app->router->post("/live", [SiteController::class, "live"]); # User authentication $app->router->get("/login", [AuthController::class, "login"]); diff --git a/www/views/layouts/main.php b/www/views/layouts/main.php index 52b316e..1f13f44 100644 --- a/www/views/layouts/main.php +++ b/www/views/layouts/main.php @@ -18,7 +18,7 @@