为什么我的flash信息不显示? CakePHP 2.2.5

时间:2013-02-21 00:17:10

标签: cakephp cakephp-2.2

为什么我在拨打用户控制器时不会显示我的flash消息?这是我的代码:

AppController.php

<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
    public $helpers=array('Session');
    public $components = array('Session');
    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Session->setFlash('This flash was set in AppController::beforeFilter.');
    }
}

UsersController.php

<?php
    class UsersController extends AppController {
        public function add() {
            $this->Session->setFlash('This flash was set in UsersController::add.');
        }
    }

我的布局... default.ctp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php echo $this->Html->charset(); ?>
    <title>My website.</title>
    <?php
        echo $this->Html->meta('icon');
        echo $this->Html->css('cake.generic');
        echo $this->fetch('meta');
        echo $this->fetch('css');
        echo $this->fetch('script');
    ?>
</head>
<body>
    <div id="container">
        <div id="header"></div>
        <div id="content">
            <?php echo $this->Session->flash(); ?>
            <?php echo $this->fetch('content'); ?>
        </div>
        <div id="footer"></div>
    </div>
</body>
</html>

add.ctp

<p>This is the add view</p>

我正在为我的网页使用内置页面控制器。每当我通过页面控制器进入页面时,它都会正确显示具有正确视图的Flash消息。但是,当我转到/ users / add时,它会显示正确的视图,但不显示flash消息。谁知道为什么?我好几天都对此感到沮丧。谢谢!

1 个答案:

答案 0 :(得分:0)

usercontroller

中进行以下更改
<?php
class UsersController extends AppControlle
{

    function beforeFilter()
    {
        parent::beforeFilter();
    }

    public function add()
    {
        $this->Session->setFlash('This flash was set in UsersController::add.');
    }
}