cakephp 2.0 flash消息未显示

时间:2014-12-02 00:35:20

标签: cakephp-2.0

我正在尝试显示错误的flash消息,但它没有显示我尝试了所有我能做的事情并且研究了它然而没有带来解决方案,我很新蛋糕所以啤酒跟我一起 thnks carts

Userscontroller

   public function add() {
    if ($this->request->is('post')) {

            $this->User->create();
            if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been created'));
            $this->redirect(array('action' => 'index'));
            } else {
            $this->redirect(array('controller'=>'pages',  'action' => 'home'));
            $this->Session->setFlash(__('The user could not be created. Please, try again.'));

            }   
          }
          }

default.thtml中

     <div id="">
    <?php echo "Flash:" ?>
    <?php  echo $this->Session->flash();?>

元素/失败

 <div class="flash flash-failure">
 <?php echo h($message); ?>
 </div>

查看文件

        Form-&gt; create('User',array('action'=&gt;'add'));?&gt;

    <div class="firstname">
        <?php echo $this->Form->input('firstname', array('class' => 'input01'));?>

    </div>


    <div class="lastname">
        <?php echo $this->Form->input('lastname', array('class' =>'input02'));?>

    </div>
    <div class = "firstname">

        <?php echo $this->Form->input('location', array('class' => 'input03'));?>

    </div>
    <div class="firstname">
        <?php echo $this->Form->input('username', array('class' =>'input03'));?>

    </div>
    <div class="email">
        <?php echo $this->Form->input('email', array('class' => 'input03'));?>

    </div>

    <div class="lastname">
        <?php echo $this->Form->input('password',array('class' => 'input02'));?>

    </div>

    <div class="email">
    <?php   echo $this->Form->input('password_confirm', array('label' => 'Confirm Password *', 'maxLength' => 255, 'title' => 'Confirm password', 'type'=>'password', 'class' =>'input03'));?>


    </div>

1 个答案:

答案 0 :(得分:0)

如果您想使用自定义元素设置闪光灯,则需要使用此语法进行设置。

$this->Session->setFlash('Error occured','failure');

第二个参数是包含flash html的自定义元素。

您可以在此处阅读会话闪存的更多详细信息:http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html

编辑: 还要检查代码是否确实输入了您的内容(&#39;帖子&#39;),我没有完整的表格,也不知道您目前正在使用哪种表格发送方式