geggleto/session

会话对象包装器

0.0.6 2016-03-21 15:47 UTC

This package is auto-updated.

Last update: 2024-08-29 03:31:32 UTC


README

围绕全局变量 _SESSION 的面向对象包装器

使用方法

//Make sure you are starting the session somewhere... session_start()

$sessionContainer = new Session();

$session->flash("error", "My error");

//In your view on the next page
$session->getFlash("error");

辅助工具

如果你使用 Twig,直接注入错误可能有所帮助。

//Inject Error's into twig
/** @var $session \Geggleto\Session */
$session = $c[Geggleto\Session::class]; // Grab from the container
$error = $session->getFlash("error"); //Grab the message

if (isset($error)) {
    $view->getEnvironment()->addGlobal("error", $error); //Inject it into twig as a global
}