Sonata News Bundle - 添加 CKEditor

Sonata News Bundle - Add CKEditor

我是 Symfony 的初学者,我正在尝试为 Sonata News Bundle 设置 CKEditor。

我到处都看了(甚至在德语论坛上,而我不会说德语!)但我找不到任何答案。

有没有人知道或解决我的问题?

谢谢大家

路易斯

我建议你使用 IvoryCKEditorBundle

下载捆绑包:

composer require egeloen/ckeditor-bundle

注册捆绑包,然后更新您的app/AppKernel。php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
            // ...
        );

        // ...
    }
}

如果您使用的是 Symfony <= 2.8:

php app/console ckeditor:install
php app/console assets:install web

如果您使用的是 Symfony >= 3.0:

php bin/console ckeditor:install
php bin/console assets:install web

然后usage

我的做法(symfony:4.3.5,奏鸣曲:3.54.1)。

下载 ckeditor JS 库并将其放在 public/js 中,即您应该拥有文件:

your_app/public/js/ckeditor/ckeditor.js

在该文件目录旁边:adapterslangpluginsskins 以及一些 js/css/md 文件。

然后覆盖基础奏鸣曲编辑模板:

{% extends '@SonataAdmin/CRUD/base_edit.html.twig' %}

{% block javascripts %}
    <script src="{{ asset('js/ckeditor/ckeditor.js') }}" type="text/javascript"></script>
    {{ parent() }}
{% endblock %}

此代码将在您的页面中包含 ckeditor,应放置在:your_app/templates/edit.html.twig

然后,添加到 "templates" 部分 edit:edit.html.twig 以便使用您创建的模板:

sonata_admin:
    title: 'Your app Admin'
    dashboard:
        blocks:
            - { type: sonata.admin.block.admin_list, position: left }
    templates:
        edit: edit.html.twig

这是文件:your_app/config/packages/sonata_admin.yaml

然后,当您从奏鸣曲管理包中添加新字段时,在 configureFormFields 中,您的 ckeditor 字段应如下所示:

->add('field_name', null, array('attr'=> array('class' => 'ckeditor')))

重要的部分是添加具有 class 属性的属性数组。 清除缓存,CKEditor 现在应该可以工作了。