从控制器发送消息以查看

时间:2015-06-03 05:28:15

标签: php model-view-controller yii

我正在尝试从我的控制器向我的视图发送错误消息。我尝试使用http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/,但我的 Flash消息未到达。我错误地重定向了吗?

CrudController.php

// execution does reach here.
Yii::app()->user->setFlash('success', "Data saved!");
$this->redirect(array('crud/admin', 'id' => $currentUser->id));

Admin.php又名我的观点

<?php if(Yii::app()->user->hasFlash('success')):?>
    <div class="info">
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>

那么如何向我的视图发送消息?我只是想向用户显示消息,老实说,我不关心如何在控制器中发生条件检查而不是查看。

var_dump(Yii::app()->user)之后

  

object(CWebUser)#21(14){[“allowAutoLogin”] =&gt;布尔(真)   [ “guest虚拟机名称”] =&GT; string(5)“Guest”[“loginUrl”] =&gt; array(1){[0] =&gt;   string(11)“/ site / login”} [“identityCookie”] =&gt; NULL [“authTimeout”] =&gt;   NULL [“autoRenewCookie”] =&gt; bool(false)[“autoUpdateFlash”] =&gt;   bool(true)[“loginRequiredAjaxResponse”] =&gt;空值   [ “_keyPrefix”: “CWebUser”:私人] =&GT;串(32)   “a68200d8b7c100a1634ae9aa04a6e79e”[“_ access”:“CWebUser”:private] =&gt;   array(0){} [“behavior”] =&gt;数组(0){}   [ “_initialized”: “CApplicationComponent”:私人] =&GT;布尔(真)   [ “_E”: “CComponent”:私人] =&GT; NULL [“_ m”:“CComponent”:private] =&gt;空值   }

1 个答案:

答案 0 :(得分:1)

我有同样的问题,但在我的情况下,我使用TbAlert(YiiBooster)。问题是我的PHP版本低于5.4 您想检查您的PHP版本吗?

相关问题