Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
71a156eb
Commit
71a156eb
authored
Jun 25, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added itemOptions for Html::ol
parent
d87afeb4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
Html.php
framework/yii/helpers/base/Html.php
+7
-3
HtmlTest.php
tests/unit/framework/helpers/HtmlTest.php
+6
-4
No files found.
framework/yii/helpers/base/Html.php
View file @
71a156eb
...
@@ -849,7 +849,8 @@ class Html
...
@@ -849,7 +849,8 @@ class Html
* @param array $options options (name => config) for the radio button list. The following options are supported:
* @param array $options options (name => config) for the radio button list. The following options are supported:
*
*
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
* This option is ignored if the `item` option below is specified.
* This option is ignored if the `item` option is specified.
* - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified.
* - item: callable, a callback that is used to generate each individual list item.
* - item: callable, a callback that is used to generate each individual list item.
* The signature of this callback must be:
* The signature of this callback must be:
*
*
...
@@ -870,13 +871,14 @@ class Html
...
@@ -870,13 +871,14 @@ class Html
$tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'ul'
;
$tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'ul'
;
$encode
=
!
isset
(
$options
[
'encode'
])
||
$options
[
'encode'
];
$encode
=
!
isset
(
$options
[
'encode'
])
||
$options
[
'encode'
];
$formatter
=
isset
(
$options
[
'item'
])
?
$options
[
'item'
]
:
null
;
$formatter
=
isset
(
$options
[
'item'
])
?
$options
[
'item'
]
:
null
;
unset
(
$options
[
'tag'
],
$options
[
'encode'
],
$options
[
'item'
]);
$itemOptions
=
isset
(
$options
[
'itemOptions'
])
?
$options
[
'itemOptions'
]
:
array
();
unset
(
$options
[
'tag'
],
$options
[
'encode'
],
$options
[
'item'
],
$options
[
'itemOptions'
]);
$results
=
array
();
$results
=
array
();
foreach
(
$items
as
$index
=>
$item
)
{
foreach
(
$items
as
$index
=>
$item
)
{
if
(
$formatter
!==
null
)
{
if
(
$formatter
!==
null
)
{
$results
[]
=
call_user_func
(
$formatter
,
$index
,
$item
);
$results
[]
=
call_user_func
(
$formatter
,
$index
,
$item
);
}
else
{
}
else
{
$results
[]
=
'<li>'
.
(
$encode
?
static
::
encode
(
$item
)
:
$item
)
.
'</li>'
;
$results
[]
=
static
::
tag
(
'li'
,
$encode
?
static
::
encode
(
$item
)
:
$item
,
$itemOptions
)
;
}
}
}
}
return
static
::
tag
(
$tag
,
"
\n
"
.
implode
(
"
\n
"
,
$results
)
.
"
\n
"
,
$options
);
return
static
::
tag
(
$tag
,
"
\n
"
.
implode
(
"
\n
"
,
$results
)
.
"
\n
"
,
$options
);
...
@@ -889,6 +891,8 @@ class Html
...
@@ -889,6 +891,8 @@ class Html
* @param array $options options (name => config) for the radio button list. The following options are supported:
* @param array $options options (name => config) for the radio button list. The following options are supported:
*
*
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
* - encode: boolean, whether to HTML-encode the items. Defaults to true.
* This option is ignored if the `item` option is specified.
* - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified.
* - item: callable, a callback that is used to generate each individual list item.
* - item: callable, a callback that is used to generate each individual list item.
* The signature of this callback must be:
* The signature of this callback must be:
*
*
...
...
tests/unit/framework/helpers/HtmlTest.php
View file @
71a156eb
...
@@ -401,12 +401,14 @@ EOD;
...
@@ -401,12 +401,14 @@ EOD;
);
);
$expected
=
<<<EOD
$expected
=
<<<EOD
<ol>
<ol>
<li>1</li>
<li
class="ti"
>1</li>
<li>abc</li>
<li
class="ti"
>abc</li>
<li><></li>
<li
class="ti"
><></li>
</ol>
</ol>
EOD;
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
ol
(
$data
));
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
ol
(
$data
,
array
(
'itemOptions'
=>
array
(
'class'
=>
'ti'
),
)));
$expected
=
<<<EOD
$expected
=
<<<EOD
<ol class="test">
<ol class="test">
<li class="item-0">1</li>
<li class="item-0">1</li>
...
...
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