[英]Yii alert widget
In view I have widget:鉴于我有小部件:
if ($content):
echo Alert::widget([
'options' => [
'class' => 'alert-info',
],
'body' => $content,
]);
endif;
That widget I want render not always, for example after save and atc.我并不总是想要渲染的那个小部件,例如在保存和 atc 之后。 Now Now I have placed that widget between if condition, maybe exists some more clear way to render widget only in some cases.
现在我已经将那个小部件放在 if 条件之间,也许存在一些更清晰的方法来仅在某些情况下呈现小部件。
I think Flash-Messages is what you want:我认为 Flash-Messages 是您想要的:
For Example:例如:
In the controller you can do something like that:在控制器中,您可以执行以下操作:
<?php
Yii::app()->user->setFlash('success', "Data saved!");
$this->redirect(array('thing/view', 'id' => 1));
And in the view :在视图中:
<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="info">
<?php echo Yii::app()->user->getFlash('success'); ?>
</div>
<?php endif; ?>
And of course you can combine it with the alert-widget or with a custom-widget.当然,您可以将它与警报小部件或自定义小部件结合使用。
See full documentation: http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/查看完整文档: http : //www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.