-
Notifications
You must be signed in to change notification settings - Fork 0
/
Html.php
executable file
·57 lines (52 loc) · 1.53 KB
/
Html.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: yidashi
* Date: 16/4/1
* Time: 下午6:28
*/
namespace yii\helpers;
class Html extends BaseHtml
{
public static function icon($name)
{
$options = ['class' => 'fa'];
if (!StringHelper::startsWith($name, 'fa-')) {
$name = 'fa-' . $name;
}
self::addCssClass($options, $name);
return self::tag('i', '', $options);
}
public static function staticControl($value, $options = [])
{
static::addCssClass($options, 'form-control-static');
$value = (string) $value;
if (isset($options['encode'])) {
$encode = $options['encode'];
unset($options['encode']);
} else {
$encode = true;
}
return static::tag('p', $encode ? static::encode($value) : $value, $options);
}
public static function activeStaticControl($model, $attribute, $options = [])
{
if (isset($options['value'])) {
$value = $options['value'];
unset($options['value']);
} else {
$value = static::getAttributeValue($model, $attribute);
}
return static::staticControl($value, $options);
}
/**
* 标红字符串中含有的关键词
* @param $q string 关键词
* @param $str string 待过滤字符串
* @return string 处理后的html
*/
public static function weight($q, $str)
{
return preg_replace('/' . $q . '/i', Html::tag('span', '$0', ['style' => 'color:#f00']), $str);
}
}