百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Y

yii2-ckeditor-widget

> 开发工具
开源

适用于 Yii2 的 CKEditor WYSIWYG 小组件。

173 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

适用于 Yii2 的 CKEditor WYSIWYG 小组件。

CKEditor Widget for Yii2

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

json
"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;

field($model, 'text')->widget(CKEditor::className(), [
        'options' => ['rows' => 6],
        'preset' => 'basic'
    ]) ?>

Using inline edition with basic preset:


use dosamigos\ckeditor\CKEditorInline;

 'basic']);?>
    This text can be edited now :)

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:

…

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
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:

…

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):

bash
$ composer install --no-interaction --prefer-source --dev

Once all required libraries are installed then do:

bash
$ 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

  • Antonio Ramirez
  • All Contributors

License

The BSD License (BSD). Please see License File for more information.


Web development has never been so fun!
www.2amigos.us

Issues· 21 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP2amigosckeditor-widgetinline-editingwidget

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具