本文整理汇总了PHP中yii\bootstrap\Alert类的典型用法代码示例。如果您正苦于以下问题:PHP Alert类的具体用法?PHP Alert怎么用?PHP Alert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Alert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
parent::init();
$session = \Yii::$app->session;
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data) {
//TOAST
if (strpos($type, 'toast') !== false) {
if (isset($this->toastTypes[$type])) {
$data = (array) $data;
foreach ($data as $i => $message) {
/* initialize css class for each alert box */
$tipo = $this->toastTypes[$type];
Toast::widget(['tipo' => $tipo, 'mensaje' => $message]);
}
$session->removeFlash($type);
}
} else {
if (isset($this->alertTypes[$type])) {
$data = (array) $data;
foreach ($data as $i => $message) {
//echo '<pre>';print_r($i);die();
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
}
$session->removeFlash($type);
}
}
}
}
示例2: api_form
public function api_form()
{
$model = new GuestbookModel();
$settings = Yii::$app->getModule('admin')->activeModules['guestbook']->settings;
ob_start();
$form = ActiveForm::begin(['enableClientValidation' => true, 'action' => Url::to(['/admin/guestbook/send'])]);
switch (Yii::$app->session->getFlash(GuestbookModel::FLASH_KEY)) {
case 'success':
$message = Yii::$app->getModule('admin')->activeModules['guestbook']->settings['preModerate'] ? Yii::t('easyii/guestbook/api', 'Message successfully sent and will be published after moderation') : Yii::t('easyii/guestbook/api', 'Message successfully added');
echo Alert::widget(['options' => ['class' => 'alert-success'], 'body' => $message]);
break;
case 'error':
echo Alert::widget(['options' => ['class' => 'alert-danger'], 'body' => Yii::t('easyii/guestbook/api', 'An error has occurred')]);
break;
}
echo $form->field($model, 'name');
if ($settings['enableTitle']) {
echo $form->field($model, 'title');
}
echo $form->field($model, 'text')->textarea();
if ($settings['enableCaptcha']) {
echo $form->field($model, 'reCaptcha')->widget(ReCaptcha::className());
}
echo Html::submitButton(Yii::t('easyii', 'Send'), ['class' => 'btn btn-primary']);
ActiveForm::end();
return ob_get_clean();
}
示例3: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (Yii::$app instanceof Application) {
$view = $this->getView();
$session = Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data) {
if (isset($this->alertTypes[$type])) {
$data = (array) $data;
foreach ($data as $i => $message) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
if ($this->delay > 0) {
$js = 'jQuery("#' . $this->options['id'] . '").fadeTo(' . $this->delay . ', 0.00, function() {
$(this).slideUp("slow", function() {
$(this).remove();
});
});';
$view->registerJs($js);
}
}
$session->removeFlash($type);
}
}
}
}
示例4: init
public function init()
{
parent::init();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
if (empty($flashes)) {
return false;
}
foreach ($flashes as $type => $message) {
//type check for more messages with the same type like "success-1"
foreach ($this->alertTypes as $k => $t) {
if (preg_match('/' . $k . '/', $type, $subpattern)) {
$type = $subpattern[0];
break;
}
}
if (isset($this->alertTypes[$type])) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type;
echo '<div class="cakebake-accounts-alert">';
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
echo '</div>';
$session->removeFlash($type);
}
}
}
示例5: init
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data)
{
if (isset($this->alertTypes[$type]))
{
$data = (array)$data;
foreach ($data as $i => $message)
{
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
}
}
示例6: run
public function run()
{
parent::init();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
$alerts = '';
foreach ($flashes as $type => $messages) {
if (!isset($this->alertTypes[$type])) {
/* initialize css class for each alert box */
$type = self::FLASH_INFO;
}
if (!is_array($messages)) {
$messages = [$messages];
}
foreach ($messages as $message) {
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type;
$body = Html::tag('i', '', ['class' => 'fa fa-' . $this->alertIcons[$type]]) . $message;
$alerts .= Alert::widget(['body' => $body, 'closeButton' => $this->closeButton, 'options' => $this->options]);
}
$session->removeFlash($type);
}
if ($alerts) {
return strtr($this->template, ['{alerts}' => $alerts]);
}
return null;
}
示例7: actionDelete
/**
* Deletes an existing ProjectManager model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($user_id)
{
Yii::$app->db->createCommand()->delete('project_manager', 'user_id =' . $user_id . '')->execute();
Yii::$app->db->createCommand()->delete('user', 'id =' . $user_id . '')->execute();
echo Alert::widget(['body' => 'El usuario se eliminó exitosamente!']);
return $this->redirect(['index']);
}
示例8: getAlert
public function getAlert()
{
if ($this->success) {
return Alert::widget(['options' => ['class' => 'alert-success'], 'body' => 'Congratulations!!! Your password has been changed...']);
} else {
return null;
}
}
示例9: run
public function run()
{
$result = [];
foreach (\Yii::$app->session->getAllFlashes() as $key => $message) {
$result[] = \yii\bootstrap\Alert::widget(['options' => ['class' => 'alert-' . ($key == 'error' ? 'danger' : $key)], 'body' => implode("<hr />", (array) $message)]);
}
return implode('', $result);
}
示例10: getNotification
/**
* @param $options
* @return string
*/
public function getNotification($options)
{
$options['class'] = $this->alertTypes[$this->type]['class'];
$msg = BootstrapAlert::widget(['body' => $this->alertTypes[$this->type]['icon'] . ' ' . $this->getMessageWithTitle(), 'options' => $options]);
$msg = Json::encode($msg);
$msg = trim($msg, '"');
$id = $this->getLayerId();
return "\$('#{$id}').append('{$msg}');";
}
示例11: run
/**
* @inheritdoc
*/
public function run()
{
foreach ($this->model->getErrors() as $attribute => $messages) {
foreach ($messages as $key => $message) {
$this->options['id'] = 'error-' . $attribute . '-' . $key;
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
}
}
}
示例12: run
/**
* @inheritdoc
*/
public function run()
{
$session = Yii::$app->getSession();
foreach ($session->getAllFlashes() as $type => $message) {
$this->options['class'] = ArrayHelper::getValue($this->alertTypes, $type, $this->alertTypes['info']);
$this->options['id'] = $this->getId() . '-' . $type;
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
$session->removeFlash($type);
}
}
示例13: run
public function run()
{
foreach ($this->getAlerts() as $alert) {
if (isset($this->options['class'])) {
Html::addCssClass($this->options, 'alert');
Html::addCssClass($this->options, 'alert-' . $alert['type']);
} else {
$this->options['class'] = 'alert alert-' . $alert['type'];
}
echo \yii\bootstrap\Alert::widget(['closeButton' => $this->closeButton, 'options' => $this->options, 'body' => $alert['body']]);
}
}
示例14: run
public function run()
{
foreach (Yii::$app->session->getAllFlashes() as $type => $message) {
if (!in_array($type, ['success', 'danger', 'error', 'warning', 'info'])) {
$type = 'info';
}
$alertType = 'alert-' . $type;
if (is_array($message)) {
$message = array_pop($message);
}
echo Alert::widget(['options' => ['class' => "alert {$alertType} {$this->alertClass}"], 'body' => $message]);
}
}
示例15: run
/**
* @inheritdoc
*/
public function run()
{
try {
if (!$this->hasModel()) {
throw new Exception(\Yii::t('skeeks/cms', "Current widget works only in form with model"));
}
if ($this->model->isNewRecord) {
throw new Exception(\Yii::t('skeeks/cms', "The image can be downloaded after you save the form data"));
}
echo $this->render('storage-image', ['model' => $this->model, 'widget' => $this]);
} catch (\Exception $e) {
echo Alert::widget(['options' => ['class' => 'alert-warning'], 'body' => $e->getMessage()]);
}
}