helper助手Html::ul的问题 [ 2.0 版本 ]
问题:
$arr = [
Html::img( '/abc/image1.jpg', [ 'alt' => '头像' ] ),
Html::img( '/abc/image2.jpg', [ 'alt' => '头像' ] ),
];
Html::ul( $arr );
结果:
<li>
<img src="/abc/image1.png" alt="头像" style="width:50px;height:50px">
</li>
<li>
<img src="/abc/image2.png" alt="头像" style="width:50px;height:50px">
</li>
得到的是转义符而不是html标签了...
哪位大哥求解决下。。。
最佳答案
-
看yii2源码,这里不想被转义就应该用
Html::ul($arr, ['encode' => false]);
/** * Generates an unordered list. * @param array|\Traversable $items the items for generating the list. Each item generates a single list item. * Note that items will be automatically HTML encoded if `$options['encode']` is not set or true. * @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. * - separator: string, the HTML code that separates items. Defaults to a simple newline (`"\n"`). * This option is available since version 2.0.7. * - 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: * * * function ($item, $index) * * * where $index is the array key corresponding to `$item` in `$items`. The callback should return * the whole list item tag. * * See [[renderTagAttributes()]] for details on how attributes are being rendered. * * @return string the generated unordered list. An empty list tag will be returned if `$items` is empty. */ public static function ul($items, $options = []) { $tag = ArrayHelper::remove($options, 'tag', 'ul'); $encode = ArrayHelper::remove($options, 'encode', true); $formatter = ArrayHelper::remove($options, 'item'); $separator = ArrayHelper::remove($options, 'separator', "\n"); $itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
共 1 条回复xiam 觉得很赞
xiam
注册时间:2016-05-01
最后登录:2017-01-04
在线时长:2小时27分
最后登录:2017-01-04
在线时长:2小时27分
- 粉丝0
- 金钱10
- 威望0
- 积分30