DLight\Application\Session
Mô tả: helper static quản lý session + flash message.
Session sẽ tự start() khi bạn gọi các method khác.
Namespace / đăng ký
- Namespace:
DLight\Application - File:
src/Application/Session.php
Public API
Session::start(): voidSession::get(string $key, mixed $default = null): mixedSession::set(string $key, mixed $value): voidSession::has(string $key): boolSession::forget(string $key): voidSession::flash(string $key, mixed $value): voidSession::getFlash(string $key, mixed $default = null): mixedSession::error(string $message): voidSession::success(string $message): voidSession::getError(): ?stringSession::getSuccess(): ?stringSession::regenerate(): voidSession::destroy(): void
Cách dùng + demo
Lưu/đọc session:
use DLight\Application\Session;
Session::set('user_id', 123);
$id = Session::get('user_id');
Flash message (tồn tại 1 request sau đó tự “già hoá”):
use DLight\Application\Session;
// Ở request hiện tại (trước khi redirect)
Session::success('Tạo mới thành công!');
// Ở request tiếp theo
$msg = Session::getSuccess();
Bảo mật session:
use DLight\Application\Session;
// Sau khi login
Session::regenerate();
// Logout
Session::destroy();