I'm building a kind of content manager for a website. Whay I need is to have a field in a form where I can put formatted text. Then I want to be able to persist it to the DB and then when the entity is displayed, I have to render it with the format!

Any clues in how to do that?

I looked in the Tinymce editor, (stfalcon's bundle) but I don't know how to make the editor (which is very nice) fit in my forms. I just displays over the other fields of the form that i have...

有帮助吗?

解决方案

To do that you do not need to use any bundle. You can implement a jquery text editor, such as redactor, ckeditor..

In your FormType just pass a class variable which appropriate with your wsyiwyg editor. For example you use Redactor to make it possible.

<script type="text/javascript">
$(document).ready(function(){
    $('.redactor').redactor();
});
</script>

In your FormType you must build a textarea with a class "redactor". To do that:

$builder->add('content', 'textarea', array('label' => "Content", 'attr' => array("class" => "redactor", "style" => "height: 300px")));

Finally, in your Twig print the content row:

{{ form_row(form.content) }}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top