gdm
gdm

Reputation: 7930

CakeEmail: no render Flash Message

In CakePhp 2.0, using CakeEmail new Component seems to not output flash message: In my controller I put:

$email = new CakeEmail(array('log'=>true));
$email->transport('Debug');

and in my view

 echo $this->Session->flash('email');

But nothing is printed out. Has that function (flash) been removed in 2.0?

Upvotes: 1

Views: 436

Answers (4)

alalmighty
alalmighty

Reputation: 21

$response = $Email->send();

$response['headers']; // headers as string
$response['message']; // message body with attachments

$this->Session->setFlash($response['headers'].$response['message']);

Make sure you have the following in your layout file.

echo $this->Session->flash();

Upvotes: 0

mark
mark

Reputation: 21743

none of the cake email libs or components or transport classes touch the session or write any such flash content. they never did as far is I know. but they return the email content as array for the DebugTransport.

so you would want to fetch the returned array and log it away:

$res = $this->Email->send();
$this->Session->setFlash($res ? 'Email sent' : 'Email not sent');

or sth like that.

Upvotes: 2

ADmad
ADmad

Reputation: 8100

In Cake 2.x the debug transport doesn't set the email content in session. Just check the return value, $contents = $email->send();. $contents will contain the headers and message so use them as required.

Upvotes: 0

scx
scx

Reputation: 2789

Of course there is flash function in cakephp 2.0 for details check it here: http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html

If you want to get ur flash message in your view you have to first set it in your Controller action.

//controller
$this->Session->setFlash('email');

//view
echo $this->Session->flash();

// The above will output.

<div id="flashMessage" class="message">
'email'.
</div>

Upvotes: 1

Related Questions