Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
yii2bootstrap
Commits
830da61d
Commit
830da61d
authored
Apr 23, 2015
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`yii\bootstrap\Html` helper added
parent
b91b3253
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
191 additions
and
0 deletions
+191
-0
BaseHtml.php
BaseHtml.php
+83
-0
CHANGELOG.md
CHANGELOG.md
+2
-0
Html.php
Html.php
+22
-0
HtmlTest.php
tests/HtmlTest.php
+84
-0
No files found.
BaseHtml.php
0 → 100644
View file @
830da61d
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\bootstrap
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
/**
* BaseHtml provides concrete implementation for [[Html]].
*
* Do not use BaseHtml. Use [[Html]] instead.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0.4
*/
class
BaseHtml
extends
\yii\helpers\Html
{
/**
* Composes icon HTML.
* @see http://getbootstrap.com/components/#glyphicons
* @param string $name icon short name, for example: 'star'
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. There are also a special options:
* - tag: string, tag to be rendered, by default 'span' is used.
* - prefix: string, prefix which should be used to compose tag class, by default 'glyphicon glyphicon-' is used.
* @return string icon HTML.
*/
public
static
function
icon
(
$name
,
$options
=
[])
{
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'span'
);
$classPrefix
=
ArrayHelper
::
remove
(
$options
,
'prefix'
,
'glyphicon glyphicon-'
);
static
::
addCssClass
(
$options
,
$classPrefix
.
$name
);
return
static
::
tag
(
$tag
,
''
,
$options
);
}
/**
* Renders Bootstrap static form control.
* @see http://getbootstrap.com/css/#forms-controls-static
* By default value will be HTML-encoded using [[encode()]], you may control this behavior
* via 'encode' option.
* @param string $value static control value.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. There are also a special options:
* - encode: boolean, whether value should be HTML-encoded or not.
* @return string generated HTML
*/
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
);
}
/**
* Generates a Bootstrap static form control for the given model attribute.
* @param \yii\base\Model $model the model object.
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs. See [[staticControl()]] for details.
* @return string generated HTML
*/
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
);
}
}
\ No newline at end of file
CHANGELOG.md
View file @
830da61d
...
...
@@ -8,7 +8,9 @@ Yii Framework 2 bootstrap extension Change Log
-
Bug #5984:
`yii\bootstrap\Activefield::checkbox()`
caused browser to link label to the wrong input (cebe)
-
Bug #7894: Fixed incorrect URL config processing at
`yii\bootstrap\Nav::items`
if route element is not a first one (nkovacs, klimov-paul)
-
Enh #29: Added support to list-groups for Collapse class (pana1990, skullcrasher)
-
Enh #1344: Added support for the static form controls via
`yii\bootstrap\Html`
(klimov-paul)
-
Enh #2546: Added
`visible`
option to
`yii\bootstrap\ButtonGroup::$buttons`
(samdark, lukBarros)
-
Enh #5207: Added support for the glyphicons via
`yii\bootstrap\Html::icon()`
(klimov-paul)
-
Enh #7633: Added
`ActionColumn::$buttonOptions`
for defining HTML options to be added to the default buttons (cebe)
-
Enh: Added
`Nav::$dropDownCaret`
to allow customization of the dropdown caret symbol (cebe)
...
...
Html.php
0 → 100644
View file @
830da61d
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\bootstrap
;
/**
* Html is an enhanced version of [[\yii\helpers\Html]] helper class dedicated to Bootstrap needs.
* This class inherits all functionality available at [[\yii\helpers\Html]] and can be used as substitute.
*
* Attention: do not confuse [[\yii\bootstrap\Html]] and [[\yii\helpers\Html]], be careful in which class
* you are using inside your views.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0.4
*/
class
Html
extends
BaseHtml
{
}
\ No newline at end of file
tests/HtmlTest.php
0 → 100644
View file @
830da61d
<?php
namespace
yiiunit\extensions\bootstrap
;
use
yii\bootstrap\Html
;
/**
* @group bootstrap
*/
class
HtmlTest
extends
TestCase
{
/**
* Data provider for [[testIcon()]]
* @return array test data
*/
public
function
dataProviderIcon
()
{
return
[
[
'star'
,
[],
'<span class="glyphicon glyphicon-star"></span>'
,
],
[
'star'
,
[
'tag'
=>
'i'
,
'prefix'
=>
'my-icon icon-'
,
],
'<i class="my-icon icon-star"></i>'
,
],
];
}
/**
* @dataProvider dataProviderIcon
*
* @param $name
* @param $options
* @param $expectedHtml
*/
public
function
testIcon
(
$name
,
array
$options
,
$expectedHtml
)
{
$this
->
assertEquals
(
$expectedHtml
,
Html
::
icon
(
$name
,
$options
));
}
/**
* @return array
*/
public
function
dataProviderStaticControl
()
{
return
[
[
'foo'
,
[],
'<p class="form-control-static">foo</p>'
],
[
'<html>'
,
[],
'<p class="form-control-static"><html></p>'
],
[
'<html></html>'
,
[
'encode'
=>
false
],
'<p class="form-control-static"><html></html></p>'
],
];
}
/**
* @dataProvider dataProviderStaticControl
*
* @param string $value
* @param array $options
* @param string $expectedHtml
*/
public
function
testStaticControl
(
$value
,
array
$options
,
$expectedHtml
)
{
$this
->
assertEquals
(
$expectedHtml
,
Html
::
staticControl
(
$value
,
$options
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment