如何设置Flash消息的显示位置?我似乎无法弄明白

时间:2015-11-20 04:49:38

标签: cakephp cakephp-2.6

在我的ContactsController中我添加了方法/操作,如果成功添加联系人,我会设置一条flash消息。并将其重定向到index.ctp

public function add() {
        if ($this->request->is('POST')) {
            $this->Contact->create();
            if ($this->Contact->save($this->request->data)) {
                $this->Session->setFlash('Contact added successfully!');
                $this->redirect(array('action'=>'index')); 
            } else {
                $this->Session->setFlash('Sorry! Contact is not added.');
            }
        }
    }

当我成功添加联系人时,会显示闪烁消息。但是当我去添加视图时,会显示Flash消息。请帮忙!

<?php echo $this->Session->flash(); ?>
    <h3>Address Book</h3>
    <table class="table table-striped">
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Zip Code</th>
        </tr>
        <?php foreach ($contacts as $contact): ?>
        <tr>
            <td>
            <?php 
            /*echo $this->Html->link($contact['Contact']['firstname']." "
                .$contact['Contact']['lastname'], 
                array('controller' => 'contacts', 'action' => 'view',
                    $contact['Contact']['id'])); */
            echo $this->Html->link($contact['Contact']['firstname']." "
                .$contact['Contact']['lastname'],
                array('action' => 'view', $contact['Contact']['id']));
            ?>
            </td>
            <td><?php echo $contact['Contact']['email']; ?></td>
            <td><?php echo $contact['Contact']['address1']; ?></td>
            <td><?php echo $contact['Contact']['city']; ?></td>
            <td><?php echo $contact['Contact']['state']; ?></td>
            <td><?php echo $contact['Contact']['zip']; ?></td>
            <!--<td><?php echo $this->HTML->link('Edit', array('action'=>'update',
                $contact['Contact']['id'])) ?>
            </td>
            <td><?php echo $this->HTML->link('Delete', array('action'=>'delete',
                $contact['Contact']['id'])) ?>
            </td>-->
        </tr>
        <?php endforeach ?>
        <?php unset($contact) ?>
    </table>
    <?php echo $this->Html->link('Add Contact', array('action'=>'add')) ?>

0 个答案:

没有答案