2012-09-09 41 views
0

我有类似这样的内容:更改闪存消息的位置

控制器。

public function add() { 
     $this->layout = 'home'; 
     $this->Session->destroy(); 

     if ($this->request->is('post')) { 
       $this->Session->setFlash(__('xxx', true)); 

     } 
    } 

查看。 home.ctp

<div id="container"> 
     <div id="header"> 
     </div> 
     <div id="content"> 

      <?php echo $this->fetch('content'); ?> 
     </div> 

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

我的问题是:为什么flash的消息没有显示在页脚?好吧,我想要的是在窗体下面显示消息,但为了简化问题,使用此代码,消息也显示在顶部。但应该在页脚中。此外,如果我删除

<?php echo $this->Session->flash(); ?> 

消息也显示在页面的顶部。

那么,我该如何改变这个Flash消息的位置呢?

编辑:

<?php var_dump($this->fetch('content')); ?> 

输出:

string '<div id="flashMessage" class="message"> The user xxxxx</div> 

<div class="users form"> 
<form action="/cake/users/add" id="UserAddForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div> <fieldset> 
<legend> 
Add User 
</legend> 

<div class="input text required error"><label for="UserUsername">Username</label><input name="data[User][username]" maxlength="50" type="text" value="" id="UserUsername" class="form-er'... (length=1187) 
+0

无关紧要'Session :: flash()'被调用,所以这不是问题。这个请求是否一定要解雇?看起来有点奇怪,也会毁掉那里的会话。 – Ross

回答

1

要设置布局,以 '家',是这样吗?您是否在views/layouts下创建了home.ctp?我问你,因为你显示的视图看起来像Cake的默认布局(default.ctp)。

对我来说,代码看起来很好配合,只要确保你显示正确的布局。

1

当我删除我的<?php echo $this->Session->flash(); ?>我没有收到Flash消息。我认为你应该考虑@ clapas的答案。