cakecoded / ckeditor
CakePHP 3.x & 4.x 的 CkEditor 插件
Requires
- php: >=5.5.9
- cakephp/cakephp: >=3.3.2 <4.0.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-20 13:29:43 UTC
README
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式是
composer require cakecoded/ckeditor
然后在 config/bootstrap.php 中添加
Plugin::load('CkEditor');
在 src/Controller/AppController.php 或您想使用 CKEditor 的任何控制器中添加
public $helpers = ['CkEditor.Ck'];
最后,在您的模板文件中,只需添加以下代码以调用 CKEditor
echo $this->Ck->input('field_name');
这等价于使用
echo $this->Form->input('field_name');
但是 CKEditor 将被加载而不是文本区域!
高级选项
您可以根据需要调整 CKEditor 和表单输入。在这方面具有完全的灵活性。
详细说明如下
echo $this->Form->input($input, $options, $ckEditorOptions, $ckEditorUrl, $ckEditorPlugins);
@param string $input
字段名称,可以是 field_name 或 model.field_name
@param array $options
选项包括 $options['label'] 用于自定义标签和其他自定义表单辅助器选项
@param array $ckEditorOptions
这将传递任何来自 http://docs.ckeditor.com/#!/guide/dev_configuration 的选项到 CKEditor
@param string $ckEditorUrl
这提供了覆盖 CKEditor URL 的选项。如果需要,您可以使用本地 URL。
@param array $ckEditorPlugins
本地安装的 CKEditor 插件的数组,每个插件作为一个子数组,格式符合 CKEditor 文档中 https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_plugins.html#addExternal 中指定的格式。
示例
使用关联字段名称
echo $this->Ck->input('category.description');
生成自定义标签
echo $this->Ck->input('field_name', ['label' => 'A unique label']);
从 http://docs.ckeditor.com/#!/guide/dev_configuration 添加 CKEditor 选项
echo $this->Ck->input('field_name', [], ['fullPage' => true, 'allowedContent' => 'true']);
加载本地版本的 CKEditor 或不同版本
echo $this->Ck->input('field_name', [], [], '/js/ckeditor.js');
加载本地安装的 CKEditor 插件
echo $this->Ck->input('field_name', [], [], null, [['myplugin', '/ckplugins/myplugin/', 'myplugin.js']]);
显示所有选项的示例
echo $this->Ck->input('field_name', ['label' => 'A unique label'], ['fullPage' => true, 'allowedContent' => 'true'], '/js/ckeditor.js', [['myplugin', '/ckplugins/myplugin/', 'myplugin.js']]);