因为是手动下载的,所以无法通过“autoload”加载Widget。
您必须通过 Composer 安装它。教程here.
在命令中输入这个。在项目的根目录:
php composer.phar require --prefer-dist mihaildev/yii2-ckeditor "*"
或者编辑 composer 文件夹中的 autoload_psr4 和 ... 文件(录制键),不推荐。
对于预设,除了标准 - BASIC - 已满,
<?= $form->field($model, 'text')>widget(\dosamigos\ckeditor\CKEditor::className(), [
'preset' => 'basic',
# 'options' => ['rows' => 6], // no need. textarea is hidden.
]) ?>
您还可以自定义:
use dosamigos\ckeditor\CKEditor;
<?php $form = ActiveForm::begin(['id' => 'help-form']); ?>
<?= $form->field($model, 'title')->textInput(); ?>
<?= $form->field($model, 'body')->widget(CKEditor::className(), [
'preset' => 'custom',
'clientOptions' => [
# 'extraPlugins' => 'pbckcode', *//Download already and in the plugins folder...*
'toolbar' => [
[
'name' => 'row1',
'items' => [
'Source', '-',
'Bold', 'Italic', 'Underline', 'Strike', '-',
'Subscript', 'Superscript', 'RemoveFormat', '-',
'TextColor', 'BGColor', '-',
'NumberedList', 'BulletedList', '-',
'Outdent', 'Indent', '-', 'Blockquote', '-',
'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'list', 'indent', 'blocks', 'align', 'bidi', '-',
'Link', 'Unlink', 'Anchor', '-',
'ShowBlocks', 'Maximize',
// 'pbckcode',
],
],
[
'name' => 'row2',
'items' => [
'Image', 'Table', 'HorizontalRule', 'SpecialChar', 'Iframe', '-',
'NewPage', 'Print', 'Templates', '-',
'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-',
'Undo', 'Redo', '-',
'Find', 'SelectAll', 'Format', 'Font', 'FontSize',
'base64image',
],
],
],
],
]);
?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end();?>
或
'clientOptions' => [
// 'skin'=> $type,
'toolbar' => [
['items' => [
'Source', '-',
] ],
['items' => [
'Bold', 'Italic', 'Underline', 'Strike', '-',
'NumberedList', 'BulletedList', '-',
] ], .........
对于其他皮肤,您可以从here手动下载皮肤或包
并在以下地址替换:
...\vendor\ckeditor\ckeditor
您可以动态使用多个皮肤。
$type = moono-dark;
#code...
'skin'=> $type,
内联:
<?php \dosamigos\ckeditor\CKEditorInline::begin(['preset' => 'custom', 'clientOptions' => [
'extraPlugins' => 'pbckcode',
'toolbarGroups' => [
['name' => 'undo'],
['name' => 'pbckcode'] // NEW PLUGIN!
]
]]) ?>