From: LeonardoBizzoni Date: Mon, 18 Apr 2022 13:53:59 +0000 (+0200) Subject: Setup pagina vtuber X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=796155efedd323baa0dc0014581ef873bece0f46;p=highschool-graduation-project Setup pagina vtuber --- 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 @@