4

AppController で:

public $helpers=array("Session","Html","Form");
public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'MainPages', 'action' => 'home'),
        'logoutRedirect' => array('controller' => 'MainPages', 'action' => 'front')
    )
);

MainPagesController で:

public function front()
{

    $this->Session->setFlash('Your stuff has been saved.');
    debug($this->Session->read('Message'));
    //etc...

デフォルトのレイアウト (default.ctp)

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

正しいフラッシュ メッセージがデバッグに表示されますが、ビューには表示されません。私は何が欠けていますか?PS ?> の後のスペースが原因ではありません。

編集: 何らかの理由で、CakePHP がセッション コンポーネントの前にセッション ヘルパーを呼び出していることを発見しました。まだそれを修正する方法を見つけようとしています。

4

4 に答える 4

0
    My setflash works in this way..
    Keep this in the App controller

    function setFlash($message, $type = 'blue') {
           //what ever the color you need..
            $arr = array('red' => 'red', 'green' => 'green', 'yellow' => 'yellow', 'gray' => 'gray', 'blue' => 'blue');
            $this->Session->setFlash($message, 'default', compact('class'), $arr[$type]);
        }

    and then call it from the controller action where you need to make the flash message as below..

    $this -> setFlash("This is flash message","red");

    now you need to make the flash in the layout(if you are using) or in your ctp file..

    <?php echo $this->Session->flash() ?>
    <?php echo $this->Session->flash('red') ?>
于 2013-03-05T09:18:03.917 に答える
0

試す

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

flash('auth')表示するには、ビューで定義する必要がありますauthentication session flash messages.

于 2013-02-18T08:01:13.270 に答える
-2

ここにエラーがあるためだと思います:

<?php echo "Flash:" ?>

セミコロンがありません

<?php echo "Flash:"; ?>
于 2013-02-17T20:57:29.610 に答える