Css 如何在cakephp中检查flash消息集是否为空

Css 如何在cakephp中检查flash消息集是否为空,css,cakephp,model-view-controller,flash-message,cakephp-2.x,Css,Cakephp,Model View Controller,Flash Message,Cakephp 2.x,我有一个登录表单,我正在控制器中设置无效登录的flash消息,如下所示: $this->Session->setFlash(__('Invalid username or password')); 并在ctp文件中显示如下消息: <div id="error" > <?php echo $this->Session->flash(); ?> </div> 加载页面时,将显示一条空的闪存消息。 如何检查$this->Session-

我有一个登录表单,我正在控制器中设置无效登录的flash消息,如下所示:

$this->Session->setFlash(__('Invalid username or password'));
并在ctp文件中显示如下消息:

<div id="error" >
<?php
echo $this->Session->flash();
?> 
</div>
加载页面时,将显示一条空的闪存消息。 如何检查
$this->Session->flash()为空,仅当其不为空时才显示div

当消息为页面加载时的空flash消息时,它如下所示:

与设置消息时的情况类似:

试试这个:

使用错误警报成功警报等创建自定义元素

/View/Elements/error\u alert.ctp

<!-- Example Bootstrap Error Alert -->
<div class="alert alert-danger">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong><?php echo $message ?></strong>
</div>
<!-- Example Bootstrap Succes Alert -->
<div class="alert alert-success">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong><?php echo $message ?></strong>
</div>
用于错误警报

$this->Session->setFlash('Success message!', 'success_alert');
$this->Session->setFlash('Error message!', 'error_alert');

为什么在
.ctp
中只从控制器的方法显示它。我需要为此定制设计如何实现?下面我已经尝试过了,但没有达到预期效果谢谢。这是正确的答案。但我覆盖了默认样式。
$this->Session->setFlash('Success message!', 'success_alert');
$this->Session->setFlash('Error message!', 'error_alert');