Browse Source

Added itemOptions for Html::ol

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
71a156ebdf
  1. 10
      framework/yii/helpers/base/Html.php
  2. 10
      tests/unit/framework/helpers/HtmlTest.php

10
framework/yii/helpers/base/Html.php

@ -849,7 +849,8 @@ class Html
* @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.
* 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.
* The signature of this callback must be:
*
@ -870,13 +871,14 @@ class Html
$tag = isset($options['tag']) ? $options['tag'] : 'ul';
$encode = !isset($options['encode']) || $options['encode'];
$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();
foreach ($items as $index => $item) {
if ($formatter !== null) {
$results[] = call_user_func($formatter, $index, $item);
} 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);
@ -889,6 +891,8 @@ class Html
* @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.
* 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.
* The signature of this callback must be:
*

10
tests/unit/framework/helpers/HtmlTest.php

@ -401,12 +401,14 @@ EOD;
);
$expected = <<<EOD
<ol>
<li>1</li>
<li>abc</li>
<li>&lt;&gt;</li>
<li class="ti">1</li>
<li class="ti">abc</li>
<li class="ti">&lt;&gt;</li>
</ol>
EOD;
$this->assertEqualsWithoutLE($expected, Html::ol($data));
$this->assertEqualsWithoutLE($expected, Html::ol($data, array(
'itemOptions' => array('class' => 'ti'),
)));
$expected = <<<EOD
<ol class="test">
<li class="item-0">1</li>

Loading…
Cancel
Save