Pat*_*bus 3 symfony ckeditor5 symfony5
我想使用 symfony5 在我的 symfony 项目上安装 CKeditor
我尝试执行本教程,但我没有管理某些部分。: https: //symfony.com/doc/current/bundles/FOSCKEditorBundle/installation.html
1/我成功执行了这个命令:
composer require friendsofsymfony/ckeditor-bundle
Run Code Online (Sandbox Code Playgroud)
2/我没有执行注册捆绑包部分,因为它已经在我的 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)
Run Code Online (Sandbox Code Playgroud)
我的树枝文件在后面,但描述字段中没有出现任何内容,这仍然是经典的文本区域
<div class="col-lg-9">
{{ form_widget(form.description) }}
</div>
Run Code Online (Sandbox Code Playgroud)
渲染的模板在源代码中显示:
<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>
Run Code Online (Sandbox Code Playgroud)
我在 Chrome 控制台中有这个:
> 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)
Run Code Online (Sandbox Code Playgroud)
谢谢大家,我对这个有点迷失了......
小智 8
下载捆绑包
$ composer require friendsofsymfony/ckeditor-bundle
Run Code Online (Sandbox Code Playgroud)
注册捆绑包
然后,更新您的 config/bundles.php:
return [
// ...
FOS\CKEditorBundle\FOSCKEditorBundle::class => ['all' => true],
// ...
];
Run Code Online (Sandbox Code Playgroud)
下载CKEditor
注册捆绑包后,您需要安装 CKEditor:
$ php bin/console ckeditor:install
Run Code Online (Sandbox Code Playgroud)
安装资产
一旦您下载了 CKEditor,您需要将其安装在 web 目录中。
$ php bin/console assets:install public
Run Code Online (Sandbox Code Playgroud)
配置树枝
然后,更新您的 /config/packages/twig.yaml
twig:
// ...
form_themes:
- '@FOSCKEditor/Form/ckeditor_widget.html.twig'
// ...
Run Code Online (Sandbox Code Playgroud)
用法
use FOS\CKEditorBundle\Form\Type\CKEditorType;
$builder->add('field', CKEditorType::class, array(
'config' => array(
'uiColor' => '#ffffff',
//...
),
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9050 次 |
| 最近记录: |