2amigos/yii2-ckeditor-widget
最新稳定版本:2.2.0
Composer 安装命令:
composer require 2amigos/yii2-ckeditor-widget
包简介
CKEditor widget for Yii2.
README 文档
README
Renders a CKEditor WYSIWYG text editor plugin widget.
Installation
The preferred way to install this extension is through composer.
Either run
composer require 2amigos/yii2-ckeditor-widget
or add
"2amigos/yii2-ckeditor-widget" : "~2.1"
to the require section of your application's composer.json file.
Skins & Plugins
This widget works with default's dev-full/stable branch of CKEditor, with a set of plugins and skins. If you wish to
configure a different skins or plugins that the one proposed, you will have to download them separately and configure
the widget's clientOptions attribute accordingly.
Usage
The library comes with two widgets: CKEditor and CKEditorInline. One is for classic edition and the other for inline
editing respectively.
Using a model with a basic preset:
use dosamigos\ckeditor\CKEditor;
<?= $form->field($model, 'text')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
]) ?>
Using inline edition with basic preset:
use dosamigos\ckeditor\CKEditorInline;
<?php CKEditorInline::begin(['preset' => 'basic']);?>
This text can be edited now :)
<?php CKEditorInline::end();?>
How to add custom plugins
This is the way to add custom plugins to the editor. Since version 2.0 we are working with the packagist version of the CKEditor library, therefore we are required to use its configuration API in order to add external plugins.
Lets add the popular Code Editor Plugin for example. This plugin would allow us to add a button to our editor's toolbar so we can add code to the content we are editing.
Assuming you have downloaded the plugin and added to the root directory of your Yii2 site. I have it this way:
+ frontend
+ -- web
+ -- pbckcode
We can now add it to our CKEditor widget. For this example I am using CKEditorInline widget. One thing you notice on
this example is that we do not use the preset attribute; this is highly important as we want to add a customized toolbar to our
widget. No more talking, here is the code:
<?php use dosamigos\ckeditor\CKEditorInline; // First we need to tell CKEDITOR variable where is our external plugin $this->registerJs("CKEDITOR.plugins.addExternal('pbckcode', '/pbckcode/plugin.js', '');"); // ... // Using the plugin <?php CKEditorInline::begin(['preset' => 'custom', 'clientOptions' => [ 'extraPlugins' => 'pbckcode', 'toolbarGroups' => [ ['name' => 'undo'], ['name' => 'basicstyles', 'groups' => ['basicstyles', 'cleanup']], ['name' => 'colors'], ['name' => 'links', 'groups' => ['links', 'insert']], ['name' => 'others', 'groups' => ['others', 'about']], ['name' => 'pbckcode'] // <--- OUR NEW PLUGIN YAY! ] ]]) ?> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> <?php CKEditorInline::end() ?>
Browse & Upload
To browse and upload files, the KCFinder plugin is used, which is disabled by default.
To enable it, just use 'kcfinder'=>true.
See this simple example code:
<?php use dosamigos\ckeditor\CKEditor; echo $form->field($model, 'text')->widget(CKEditor::className(), [ 'kcfinder' => true, ]);
The upload folder name is upload in the root web directory by default.
You can set options for the kcfOptions parameter, and can find all KCFinder's options in this link: https://kcfinder.sunhater.com/install
For change upload directory or change some options you can see this advanced example code:
<?php use dosamigos\ckeditor\CKEditor; echo $form->field($model, 'text')->widget(CKEditor::className(), [ 'kcfinder' => true, 'kcfOptions' => [ 'uploadURL' => '@web/upload', 'uploadDir' => '@webroot/upload', 'access' => [ // @link http://kcfinder.sunhater.com/install#_access 'files' => [ 'upload' => true, 'delete' => true, 'copy' => true, 'move' => true, 'rename' => true, ], 'dirs' => [ 'create' => true, 'delete' => true, 'rename' => true, ], ], 'types' => [ // @link http://kcfinder.sunhater.com/install#_types 'files' => [ 'type' => '', ], ], ], ]);
About extra assets
You maybe wonder why there is file dosamigos-ckeditor.widget.js. The reason is that due to the way Yii2 works with
forms and Cross-Site Request Forgery (csrf). CKEditor does not trigger the on change event nor collects the CSRF token
when using file uploads.
The asset tackles both issues.
Testing
To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do
the following (assuming you have composer installed on your computer):
$ composer install --no-interaction --prefer-source --dev
Once all required libraries are installed then do:
$ vendor/bin/phpunit
Further Information
Please, check the CKEditor plugin site documentation for further information about its configuration options.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The BSD License (BSD). Please see License File for more information.
Web development has never been so fun!
www.2amigos.us
2amigos/yii2-ckeditor-widget 适用场景与选型建议
2amigos/yii2-ckeditor-widget 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82M 次下载、GitHub Stars 达 169, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「CKEditor」 「extension」 「yii」 「widget」 「yii2」 「yii 2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 2amigos/yii2-ckeditor-widget 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 2amigos/yii2-ckeditor-widget 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 2amigos/yii2-ckeditor-widget 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 1.82M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 173
- 点击次数: 30
- 依赖项目数: 66
- 推荐数: 2
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04