alexantr/yii2-ckeditor

CKEditor 小部件用于 Yii 2

安装次数: 26,766

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 1

开放问题: 3

类型:yii2-extension

2.2.0 2018-08-20 11:04 UTC

This package is auto-updated.

Last update: 2024-09-23 14:54:50 UTC


README

此扩展为 CKEditor 小部件提供对 Yii 框架 2.0 的支持。

Latest Stable Version Total Downloads License Build Status

安装

通过 composer 安装扩展

composer require alexantr/yii2-ckeditor

CKEditor 版本

此扩展与稳定的 standard-all 版本兼容。该 standard-all 版本包含所有官方 CKSource 插件,其中只有来自 standard 安装预设的插件被编译进 ckeditor.js 文件并在配置中启用。

注意:从版本 2.0 开始,扩展从 CDN 加载 CKEditor。

使用方法

以下视图文件中的代码将渲染一个 CKEditor 小部件

<?= alexantr\ckeditor\CKEditor::widget(['name' => 'attributeName']) ?>

配置 CKEditor 选项 应使用 clientOptions 属性进行

<?= alexantr\ckeditor\CKEditor::widget([
    'name' => 'attributeName',
    'clientOptions' => [
        'extraPlugins' => 'autogrow,colorbutton,colordialog,iframe,justify,showblocks',
        'removePlugins' => 'resize',
        'autoGrow_maxHeight' => 900,
        'stylesSet' => [
            ['name' => 'Subscript', 'element' => 'sub'],
            ['name' => 'Superscript', 'element' => 'sup'],
        ],
    ],
]) ?>

如果您想在 ActiveForm 中使用 CKEditor 小部件,可以这样做

<?= $form->field($model, 'attributeName')->widget(alexantr\ckeditor\CKEditor::className()) ?>

使用全局配置(预设)

为了避免在每个小部件中重复相同的配置,您可以在 @app/config/ckeditor.php 中设置全局配置。小部件的 clientOptions 选项将与此配置合并。

您可以使用 presetPath 属性更改默认路径

<?= alexantr\ckeditor\CKEditor::widget([
    'name' => 'attributeName',
    'presetPath' => '@backend/config/my-ckeditor-config.php',
]) ?>