You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
<?php |
|
/** |
|
* @copyright Copyright (c) 2008 Yii Software LLC |
|
* @link http://www.yiiframework.com/ |
|
* @license http://www.yiiframework.com/license/ |
|
*/ |
|
|
|
namespace yii\bootstrap\helpers\base; |
|
|
|
use yii\bootstrap\enum\Enum; |
|
use yii\helpers\Html; |
|
|
|
/** |
|
* Alert provides methods to make use of bootstrap alert messages in your application |
|
* |
|
* @author Antonio Ramirez <amigo.cobos@gmail.com> |
|
* @since 2.0 |
|
*/ |
|
class Alert |
|
{ |
|
|
|
/** |
|
* constants |
|
*/ |
|
const CLASS_NAME = 'alert'; |
|
const TYPE_DEFAULT = ''; |
|
const TYPE_SUCCESS = 'alert-success'; |
|
const TYPE_INFORMATION = 'alert-info'; |
|
const TYPE_ERROR = 'alert-error'; |
|
const SIZE_BLOCK = 'alert-block'; |
|
|
|
/** |
|
* Generates an alert box |
|
* @param $message |
|
* @param array $htmlOptions |
|
* @param bool $dismiss whether to display dismissal link or not |
|
* @return string |
|
*/ |
|
public static function create($message, $htmlOptions = array(), $dismiss = true) |
|
{ |
|
// TODO: this method may should be added to ArrayHelper::add or ArrayHelper::append? |
|
if (isset($htmlOptions['class'])) |
|
$htmlOptions['class'] .= ' ' . static::CLASS_NAME; |
|
else |
|
$htmlOptions['class'] = static::CLASS_NAME; |
|
|
|
ob_start(); |
|
echo Html::beginTag('div', $htmlOptions); |
|
if ($dismiss) |
|
echo Button::closeLink('×', Enum::ALERT); |
|
echo $message; |
|
echo Html::endTag('div'); |
|
return ob_get_clean(); |
|
} |
|
} |