0

我在 Cakephp 会话中遇到了非常奇怪的问题。如果我没有在控制器中包含电子邮件代码,会话正在工作。并且会话将设置并且它将在视图中可用。

$this->Email->to = 'email@example.com';
$this->Email->subject = 'Website request';
$this->Email->send($this->data['Contact']['message']);
$this->Session->write('success','After Sending Email.');
// This will not save session.

但如果我包含电子邮件代码并设置会话,它将不会设置会话,也不会在视图中可用。

//$this->Email->to = 'email@example.com';
//$this->Email->subject = 'Website request';
//$this->Email->send($this->data['Contact']['message']);
$this->Session->write('success','After Sending Email.');
// This will save session as email code is commented

现在真正的问题来了。当我在发送电子邮件之前设置会话时,它将在视图中可用,但如果我在发送电子邮件后设置会话,它在视图文件中不可用。请检查下面的代码块是否相同。

$this->Session->write('success','After Sending Email.');
$this->Email->to = 'email@example.com';
$this->Email->subject = 'Website request';
$this->Email->send($this->data['Contact']['message']);
// This will save session as its set before sending email

有人可以弄清楚我的代码或 CakePHP 出了什么问题吗?

4

0 回答 0