如何在Symfony 5上安装Ckeditor?

3
我希望能够在我的Symfony5项目中安装CKeditor。
我尝试按照以下教程进行操作,但是有些部分我没有成功:https://symfony.com/doc/current/bundles/FOSCKEditorBundle/installation.html 1. 我已经成功执行了以下命令:
composer require friendsofsymfony/ckeditor-bundle

2/ 我没有执行注册bundle的部分,因为它已经在我的config/bundles.php中(所以我认为文档已经不是最新的了)

3/ 我将这个添加到了我的fileType.php中

use FOS\CKEditorBundle\Form\Type\CKEditorType;

class PropertyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
->add('description', CKEditorType::class)

我的twig文件落后了,但是在描述字段中没有任何内容显示,该字段仍然是一个经典的文本区域。

<div class="col-lg-9">
    {{ form_widget(form.description) }}
</div>

渲染后的模板在源代码中显示为:

<div class="col-lg-9">
     <textarea id="property_description" name="property[description]" required="required"></textarea>
<script type="text/javascript">
            var CKEDITOR_BASEPATH = "/bundles/fosckeditor/";
</script>
<script type="text/javascript" src="/bundles/fosckeditor/ckeditor.js"></script>
<script type="text/javascript">
        if (CKEDITOR.instances["property_description"]) { CKEDITOR.instances["property_description"].destroy(true); delete CKEDITOR.instances["property_description"]; }
        CKEDITOR.replace("property_description", {"language":"en"});
</script>

我在谷歌浏览器控制台中看到了这个:

> Failed to load resource: the server responded with a status of 404
> (Not Found) new:95 Uncaught ReferenceError: CKEDITOR is not defined
>     at new:95 :8000/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)

感谢大家,我对这个有点迷惑...
2个回答

8

下载捆绑软件包

$ composer require friendsofsymfony/ckeditor-bundle

注册Bundle

接下来,更新你的config/bundles.php文件:

return [

 // ...

FOS\CKEditorBundle\FOSCKEditorBundle::class => ['all' => true],

// ...

];

下载 CKEditor

一旦您注册了捆绑包,就需要安装 CKEditor:

$ php bin/console ckeditor:install

安装资源

下载CKEditor后,您需要将其安装到Web目录中。

$ php bin/console assets:install public

配置Twig

接下来,更新你的 /config/packages/twig.yaml 文件。

twig:
    // ...
    form_themes:
        - '@FOSCKEditor/Form/ckeditor_widget.html.twig'
    // ...

使用方法

use FOS\CKEditorBundle\Form\Type\CKEditorType;

$builder->add('field', CKEditorType::class, array(
    'config' => array(
        'uiColor' => '#ffffff',
        //...
    ),
));

2
你是否执行了此部分文档中记录的php bin/console ckeditor:install命令?
404错误可能是由于无法找到ckeditor.js文件导致的,因此预计会出现CKEDITOR未定义的错误。你可以阅读Symfony命令安装ckeditor的文档以获取更多信息。

1
谢谢,我可能误读了文档的这一部分。在Symfony 5中,解决了我的问题: 1- composer require friendsofsymfony/ckeditor-bundle 2- php bin/console ckeditor:install 3- php bin/console assets:install public - Patrick Valibus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接