项目作者: imaxwen

项目描述 :
CKEditor widget for yii2, with ckfinder&elfinder integrated
高级语言: JavaScript
项目地址: git://github.com/imaxwen/yii2-ckeditor-widget.git
创建时间: 2016-09-28T09:20:10Z
项目社区:https://github.com/imaxwen/yii2-ckeditor-widget

开源协议:MIT License

下载


yii2-ckeditor-widget

CKEditor widget for yii2, support ckfinder,elfinder
This repo was forked from 2amigos/yii2-ckeditor-widget.
I made some customization.

Installation

  1. composer require maxwen/yii2-ckeditor-widget

Configuration

Inorder to add your custom configure,
you need to add an controllerMap to you config/main.php:

  1. 'controllerMap' => [
  2. 'ckeditor' => [
  3. 'class' => 'maxwen\ckeditor\controllers\EditorController',
  4. 'viewPath' => '@vendor/maxwen/yii2-ckeditor-widget/views/editor'
  5. ]
  6. ]

Then add you custom configure into params.php:
see CKEditor.config

  1. // CKEditor config rewrite
  2. 'ckeditorConfig' => [
  3. // custom options
  4. 'language' => 'en',
  5. 'font_names' => 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana',
  6. 'toolbar' => 'Full',
  7. 'skin' => 'your skin name here'
  8. // etc...
  9. ],

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:

  1. use maxwen\ckeditor\CKEditor;
  2. <?= $form->field($model, 'text')->widget(CKEditor::className(), [
  3. 'options' => ['rows' => 6],
  4. 'editorConfig' => [
  5. 'customConfig' => 'http://yourdoman.com/ckeditor/config.js',
  6. // etc ...
  7. ]
  8. ]) ?>

Using inline edition with basic preset:

  1. use maxwen\ckeditor\CKEditorInline;
  2. <?php CKEditorInline::begin([
  3. 'editorConfig' => [
  4. // ...
  5. ]
  6. ]);?>
  7. This text can be edited now :)
  8. <?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:

  1. + frontend
  2. + -- web
  3. + -- 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:

  1. <?php
  2. use maxwen\ckeditor\CKEditorInline;
  3. // First we need to tell CKEDITOR variable where is our external plufin
  4. $this->registerJs("CKEDITOR.plugins.addExternal('pbckcode', '/pbckcode/plugin.js', '');");
  5. // ...
  6. // Using the plugin
  7. <?php CKEditorInline::begin(['preset' => 'custom', 'clientOptions' => [
  8. 'extraPlugins' => 'pbckcode',
  9. 'toolbarGroups' => [
  10. ['name' => 'undo'],
  11. ['name' => 'basicstyles', 'groups' => ['basicstyles', 'cleanup']],
  12. ['name' => 'colors'],
  13. ['name' => 'links', 'groups' => ['links', 'insert']],
  14. ['name' => 'others', 'groups' => ['others', 'about']],
  15. ['name' => 'pbckcode'] // <--- OUR NEW PLUGIN YAY!
  16. ]
  17. ]]) ?>
  18. <p>
  19. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
  20. dolore magna aliqua.
  21. </p>
  22. <?php CKEditorInline::end() ?>

About CKFinder

CKFinder is a commercial software, this repo just contains a demo version, you can purchase the full version here.

Further Information

Please, check the CKEditor plugin site documentation for further information about its configuration options.