myzero1/yii2-ckeditor

CKEditor widget for Yii 2

Installs: 116

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

4.11.2 2019-03-04 04:29 UTC

This package is not auto-updated.

Last update: 2024-12-17 18:16:43 UTC


README

This extension renders a CKEditor widget for Yii framework 2.0.

License

Installation

Install extension through composer:

Either run

php composer.phar require "myzero1/yii2-ckeditor" "*"

or add

"myzero1/yii2-ckeditor" : "*"

to the require section of your application's composer.json file.

Config the action for upload

Add the section of your application's main.json file, as flowing:


return [
    ......
    'controllerNamespace' => 'backend\controllers',
    'controllerMap' => [
        'ckeditor' => [
            'class' => 'myzero1\ckeditor\CKditorController',
            'config' => [
                'imageFieldName' => 'upload',
                'imageMaxSize' => 1024*1024*2, // 2M = 1024*1024*2
                'imageAllowFiles' => ['.jpg', '.jpeg', '.png', '.gif'],
                'imagePathFormat' => '/upload/image/{yyyy}{mm}{dd}/{time}{rand:8}',
            ],
        ]
    ],
    'bootstrap' => ['log'],
    ......

Usage

The following code in a view file would render a CKEditor widget:

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

Configuring the CKEditor options should be done using the clientOptions attribute:

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

If you want to use the CKEditor widget in an ActiveForm, it can be done like this:

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

If you want to use the CKEditor widget in an ActiveForm,and to configuring the CKEditor options, it can be done like this:

<?= $form->field($model, 'attributeName')->widget(myzero1\ckeditor\CKEditor::className(), [
        'clientOptions' => [
            'selectMultiple' => true,
            'filebrowserImageUploadUrl' => '/ckeditor/upload-image',
            'imageUploadUrl' => '/ckeditor/upload-image',
            'extraPlugins' => 'autogrow,colorbutton,colordialog,iframe,justify,showblocks,preview,image2',
            // 'extraPlugins' => 'autogrow,colorbutton,colordialog,iframe,justify,showblocks,image2,preview,easyimage',
            'removePlugins' => 'resize,image',
            'autoGrow_maxHeight' => 900,
            'stylesSet' => [
                ['name' => 'Subscript', 'element' => 'sub'],
                ['name' => 'Superscript', 'element' => 'sup'],
            ],
        ],
    ]) ?>