Class yii\bootstrap\Alert

Inheritanceyii\bootstrap\Alert » yii\bootstrap\Widget » yii\base\Widget
Uses Traitsyii\bootstrap\BootstrapWidgetTrait
Available since version2.0

Alert renders an alert bootstrap component.

For example,

echo Alert::widget([
    'options' => [
        'class' => 'alert-info',
    ],
    'body' => 'Say hello...',
]);

The following example will show the content enclosed between the \yii\bootstrap\begin() and \yii\bootstrap\end() calls within the alert box:

Alert::begin([
    'options' => [
        'class' => 'alert-warning',
    ],
]);

echo 'Say hello...';

Alert::end();

See also http://getbootstrap.com/components/#alerts.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$body string The body content in the alert component. yii\bootstrap\Alert
$clientEvents array The event handlers for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$clientOptions array The options for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$closeButton array|false The options for rendering the close button tag. yii\bootstrap\Alert
$options array The HTML attributes for the widget container tag. yii\bootstrap\Widget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getView() yii\bootstrap\BootstrapWidgetTrait
init() Initializes the widget. yii\bootstrap\Alert
run() Renders the widget. yii\bootstrap\Alert

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
initOptions() Initializes the widget options. yii\bootstrap\Alert
registerClientEvents() Registers JS event handlers that are listed in $clientEvents. yii\bootstrap\BootstrapWidgetTrait
registerPlugin() Registers a specific Bootstrap plugin and the related events yii\bootstrap\BootstrapWidgetTrait
renderBodyBegin() Renders the close button if any before rendering the content. yii\bootstrap\Alert
renderBodyEnd() Renders the alert body (if any). yii\bootstrap\Alert
renderCloseButton() Renders the close button. yii\bootstrap\Alert

Property Details

$body public property

The body content in the alert component. Note that anything between the \yii\bootstrap\begin() and \yii\bootstrap\end() calls of the Alert widget will also be treated as the body content, and will be rendered before this.

public string $body null
$closeButton public property

The options for rendering the close button tag. The close button is displayed in the header of the modal window. Clicking on the button will hide the modal window. If this is false, no close button will be rendered.

The following special options are supported:

  • tag: string, the tag name of the button. Defaults to 'button'.
  • label: string, the label of the button. Defaults to '×'.

The rest of the options will be rendered as the HTML attributes of the button tag. Please refer to the Alert documentation for the supported HTML attributes.

public array|false $closeButton = []

Method Details

init() public method

Initializes the widget.

public void init ( )
initOptions() protected method

Initializes the widget options.

This method sets the default values for various options.

protected void initOptions ( )
renderBodyBegin() protected method

Renders the close button if any before rendering the content.

protected string renderBodyBegin ( )
return string

The rendering result

renderBodyEnd() protected method

Renders the alert body (if any).

protected string renderBodyEnd ( )
return string

The rendering result

renderCloseButton() protected method

Renders the close button.

protected string renderCloseButton ( )
return string

The rendering result

run() public method

Renders the widget.

public void run ( )