--- /dev/null
+<?php
+
+use app\core\Application;
+
+class m_1650287984_vtuberTable
+{
+ public function up()
+ {
+ $db = Application::$app->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);
+ }
+}
+?>
use app\core\BaseController;
use app\core\Request;
+use app\models\Vtubers;
class SiteController extends BaseController {
public function home() {
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 ]);
}
}
-?>
}
}
+ echo " <script>alert('validate fatto!')</script>";
return empty($this->errors);
}
--- /dev/null
+<?php
+
+namespace app\models;
+
+use app\core\DbModel;
+
+class Vtubers extends DbModel
+{
+ public string $username = "";
+ public string $link = "";
+
+ public function tableName(): string
+ {
+ return "vtubers";
+ }
+
+ public function attributes(): array {
+ return [ "username", "link" ];
+ }
+
+ public function register()
+ {
+ return $this->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";
+ }
+}
$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"]);
<div class="collapse navbar-collapse" id="navbarNav" style="display: flex;">
<ul class="navbar-nav">
<li class="nav-item">
- <a class="nav-link" href="/contact">Contact</a>
+ <a class="nav-link" href="/live">Live</a>
</li>
</ul>
--- /dev/null
+<h1>Live page</h1>
+
+<div class="container">
+ <?php $form = app\core\forms\Form::begin("", "post"); ?>
+ <?php echo $form->field($model, "Link"); ?>
+ <button type="submit" class="btn btn-primary">Submit</button>
+ <?php app\core\forms\Form::end(); ?>
+</div>