wdmg / yii2-widgets
Yii2 Widgets 组件集合
1.1.0
2023-07-07 06:43 UTC
Requires
- yiisoft/yii2: ^2.0.33
- yiisoft/yii2-bootstrap: *
README
Yii2 Widgets
为 Yii2 定制的组件集合
NavContents::widget()
该组件解析你的 HTML 代码,查找 h1-h6 标题,并创建带有正确 href 的导航列表,然后在其内容之前渲染一个 Bootstrap 导航。
如果 h1-h6 标题没有 id
属性,它将自动生成。标题的其他属性,如 class
、style
或 data
也会被保存。
MenuContents::widget()
与 NavContents::widget()
类似,但输出时形成普通的 <ul>
列表。
要求
- PHP 5.6 或更高版本
- Yii2 v.2.0.33 及更高版本
安装
要在控制台中安装组件,请运行以下命令
$ composer require "wdmg/yii2-widgets"
使用方法
NavContents::widget() 在视图实例中的使用示例
<?php
use wdmg\widgets\NavContents;
$content = '<h1>Header H1</h1><p>Some text, some text...</p><p>Some text, some text...</p>'
?>
<?= NavContents::widget([
'id' => "list1",
'content' => $content, // where `$content` the html source with h1-h6 headers
'renderContent' => true, // if `true` (by default) render content html after table of contents
'transliterate' => true, // if need to convert href and ID to Latin (Cyrillic for example)
'options' => [
'class' => 'nav nav-stacked'
],
... // and other options for yii\bootstrap\Nav::widget()
]); ?>
MenuContents::widget() 在视图实例中的使用示例
<?php
use wdmg\widgets\MenuContents;
$content = '<h1 id="test-header" class="header">Header H1</h1><p>Some text, some text...</p><p>Some text, some text...</p>'
?>
<?= MenuContents::widget([
'id' => "list2",
'content' => $content, // where `$content` the html source with h1-h6 headers
'renderContent' => true, // if `true` (by default) render content html after table of contents
'transliterate' => true, // if need to convert href and ID to Latin (Cyrillic for example)
'options' => [
'class' => 'list-toc'
],
... // and other options for yii\widgets\Menu::widget()
]); ?>
LangSwitcher::widget() 在仪表板视图实例中的使用示例
<?php
use wdmg\widgets\LangSwitcher;
<?php
echo LangSwitcher::widget([
'label' => 'Language version',
'model' => $model,
'renderWidget' => 'button-group',
'createRoute' => 'news/create', // string or array
'updateRoute' => 'news/update', // string or array
'supportLocales' => $this->context->module->supportLocales,
'versions' => (isset($model->source_id)) ? $model->getAllVersions($model->source_id, true) : $model->getAllVersions($model->id, true),
'options' => [
'id' => 'locale-switcher',
'class' => 'pull-right'
]
]);
?>
AliasInput::widget() 在仪表板视图实例中的使用示例
<?php
use wdmg\widgets\AliasInput;
<?= $form->field($model, 'alias')->widget(AliasInput::class, [
'labels' => [
'edit' => 'Edit',
'save' => 'Save'
],
'options' => [
'baseUrl' => $model->url
]
])->label('Post URL'); ?>
状态和版本 [开发中]
- v.1.1.0 - 更新版权信息
- v.1.0.4 - LangSwitcher 中的 URL 选项
- v.1.0.3 - 添加 AliasInput::widget()
- v.1.0.2 - 添加 LangSwitcher::widget()
- v.1.0.1 - 更新依赖项
- v.1.0.0 - 添加 NavContents::widget() 和 MenuContents::widget()