开发者

Problems with getFlash and setFlash in Yii

Ok, I know what I'm about to say is going to be super vague, but hear me out:

I want to use flash messages because I like the idea of them, but they don't seem to always work for me.

Here is my workflow:

  1. User creates开发者_高级运维 a group on page A
  2. I send an email notification to members of the new group
  3. I set the flash message "Success!"
  4. I redirect the user to the newly created group and display the "Success!" flash message.

The problem is after I redirect the user, the flash messages are no longer in the $_SESSION. To make this even more strange, if I take out the step where I send email notifications, it DOES work. WTF?

Has anyone else experienced similar issues with flash messages? Does anyone have any insight into why sending the email would affect the flash messages?

I think at this point I'm just going to stick with setState and manually remove it after displaying them.


Now You can set a property autoUpdateFlash of CWebUser component to false. In this case flash message will be removed only after usage.


How is the email being sent? I know using the Yii Mail extension (a swiftmailer wrapper I think) in "debug" mode uses the setFlash method, so perhaps that's wiping out the array somehow...?

The "flash" variables are updated by the init() method of CWebUser, so if there is an extra call to CWebUser it's possible that's what is clearing out the flash variables.

Considering that you set the flash AFTER the email though, I'm not sure how that would happen. My only other guess besides the "debug mode" thing (not a problem if you are just using the PHP mail methods though) is that sending mail is triggering an extra redirect somewhere.

If you have a PHP debugger like XDebug installed I would set a breakpoint in the getFlash and setFlash code and get a look at what is happening that way.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜