当我想回显存储在会话中的数据然后取消设置特定会话时...没有任何反应。当我使用session_unset(特定会话)时,它会销毁所有会话。有什么想法吗?
function danger($text)
{
echo "<div class='alert alert-danger alert-dismissable'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>" . $text . "</div>";
}
public function success($text)
{
echo "<div class='alert alert-success alert-dismissable'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>" . $text . "</div>";
}
function flash($session)
{
return $session;
unset($session);
}
用法:
function checkErrors()
{
if (isset($_SESSION['login_error']))
{
return danger(flash($_SESSION['login_error']));
} elseif (isset($_SESSION['login_true']))
{
return success(flash($_SESSION['login_true']));
}
}
答案 0 :(得分:1)
尝试添加临时变量,然后取消设置变量,如下所示:
function flash($session)
{
$temp = $session;
unset($session);
return $temp;
}
你的功能应该是:
function danger($text)
{ $display = "<div class='alert alert-danger alert-dismissable'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>" . $text . "</div>";
return $display;
}
public function success($text)
{
$display = "<div class='alert alert-success alert-dismissable'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>" . $text . "</div>";
return $display;
}