Reputation: 2418
I am trying to send an error message from my controller to my view. I tried to use http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/ but my flash message is not arriving. Am I redirecting incorrectly?
CrudController.php
// execution does reach here.
Yii::app()->user->setFlash('success', "Data saved!");
$this->redirect(array('crud/admin', 'id' => $currentUser->id));
Admin.php aka my view
<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="info">
<?php echo Yii::app()->user->getFlash('success'); ?>
</div>
<?php endif; ?>
So how do I send a message to my view? I just want to show the message to the user, I honestly don't care how except that the conditional check happens in the controller not view.
After var_dump(Yii::app()->user)
object(CWebUser)#21 (14) { ["allowAutoLogin"]=> bool(true) ["guestName"]=> string(5) "Guest" ["loginUrl"]=> array(1) { [0]=> string(11) "/site/login" } ["identityCookie"]=> NULL ["authTimeout"]=> NULL ["autoRenewCookie"]=> bool(false) ["autoUpdateFlash"]=> bool(true) ["loginRequiredAjaxResponse"]=> NULL ["_keyPrefix":"CWebUser":private]=> string(32) "a68200d8b7c100a1634ae9aa04a6e79e" ["_access":"CWebUser":private]=> array(0) { } ["behaviors"]=> array(0) { } ["_initialized":"CApplicationComponent":private]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL }
Upvotes: 2
Views: 728
Reputation: 75
I have the same problem, but in my case I use TbAlert (YiiBooster). The problem is my PHP version is below 5.4 Would you like to check your PHP Version?
Upvotes: 1