Alert

Alerts can be used to conveniently display the flash messages of Yii's session component.

Default message and structure


// In some controller
<?php Yii::$app->session->setFlash('default', 'Default message') ?>

// In your view or layout
<?= \macgyer\yii2materializecss\widgets\Alert::widget(); ?>

<div id="w0-default-0" class="alert default">
    <div class="card-panel">Default message</div>
</div>

Rendered result

Default message

Contextual messages

Every flash message will be rendered in a separate element with the contextual CSS class applied to it.

The following contextual classes are pre-defined:

  • error
  • danger
  • success
  • info
  • warning

Define the appearance of each alert category in your CSS file.

If you need additional contextual classes or require other CSS classes, simply assign them to $alertLevels. This property will be merged with $predefinedAlertLevels.


// In some controller
<?php Yii::$app->session->setFlash('success', 'Success message') ?>
<?php Yii::$app->session->setFlash('error', 'Error message') ?>

// In your view or layout
<?= \macgyer\yii2materializecss\widgets\Alert::widget(); ?>

<div id="w1-success-0" class="alert success">
    <div class="card-panel">Success message</div>
</div>

<div id="w1-error-0" class="alert error">
    <div class="card-panel">Error message</div>
</div>

Rendered result

Success message
Error message

Please note:
The alert box has been styled to be displayed accordingly.