-
Notifications
You must be signed in to change notification settings - Fork 0
Views
Tirapong Chaiyakun edited this page Sep 19, 2026
·
1 revision
ไฟล์อยู่ที่ Views/ (เปลี่ยนได้ด้วย VIEW_PATH)
ชื่อวิวใช้จุดแทนโฟลเดอร์ เช่น errors.403 → Views/errors/403.php
$this->view('index', ['title' => 'หน้าแรก']);หรือ
\Core\View::render('index', ['title' => 'หน้าแรก']);ในเทมเพลต
<!doctype html>
<html>
<head>
<title><?= $title ?></title>
<link rel="stylesheet" href="<?= \Core\View::asset('css/app.css') ?>">
</head>
<body>
<form method="post">
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
</form>
<script src="<?= \Core\View::asset('js/app.js') ?>"></script>
</body>
</html>View::asset('css/app.css') ชี้ไปที่ public/assets/css/app.css
ข้อมูลที่ส่งเข้าวิวถูก sanitize และมี $csrf_token ให้อัตโนมัติ
ห้ามใช้ .. ในชื่อวิว
View::render(..., withJs: true) จะฝัง window.appData ในหน้า
หน้า error ตัวอย่างอยู่ที่ Views/errors/403.php
use Core\Http;
Http::timeout(15);
$res = Http::get('https://api.example.com/health');
$res = Http::post('https://api.example.com/users', ['name' => 'Deawx']);
$res = Http::withToken($jwt, 'GET', 'https://api.example.com/me');ผลที่คืนมา
[
'status' => 200,
'headers' => [...],
'body' => '...',
'json' => [...], // ถ้า Content-Type เป็น JSON
'info' => [...],
]ถ้าล้มเหลวจะมีคีย์ error
อนุญาตเฉพาะ http และ https
ตรวจ SSL ของปลายทางอยู่แล้ว