我想在项目的管理面板中使用Ckeditor或markdown文本编辑器
我在项目中安装了FormatterBundle,Ivory \ CkeditorBundle和Knp \ MarkdownBundle ....
在我的PostAdmin.php
中namespace Main\Bundle\MainBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class PostsAdmin extends Admin
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('id')
->add('title')
->add('shortDescription')
->add('text', 'sonata_formatter_type', array(
'source_field' => 'text',
'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)),
'format_field' => 'text',
'target_field' => 'text',
'ckeditor_context' => 'default',
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher()
))
->add('created')
->add('updated')
->with('Gallery')
->add('gallery', 'sonata_type_model_list', array(
'cascade_validation' => true,
), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'link_parameters' => array('context' => 'posts'),
'admin_code' => 'sonata.media.admin.gallery'
)
)
->end()
;
}
我的config.php是..
sonata_formatter:
formatters:
markdown:
service: sonata.formatter.text.markdown
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig #keep this commented unless you are using media bundle.
text:
service: sonata.formatter.text.text
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
rawhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
richhtml:
service: sonata.formatter.text.raw
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
- sonata.media.formatter.twig
twig:
service: sonata.formatter.text.twigengine
extensions: [] # Twig formatter cannot have extensions
ckeditor:
templates:
browser: 'SonataFormatterBundle:Ckeditor:browser.html.twig'
upload: 'SonataFormatterBundle:Ckeditor:upload.html.twig'
ivory_ck_editor:
default_config: default
configs:
default:
filebrowserBrowseRoute: admin_sonata_media_media_ckeditor_browser
filebrowserImageBrowseRoute: admin_sonata_media_media_ckeditor_browser
# Display images by default when clicking the image dialog browse button
filebrowserImageBrowseRouteParameters:
provider: sonata.media.provider.image
filebrowserUploadRoute: admin_sonata_media_media_ckeditor_upload
filebrowserUploadRouteParameters:
provider: sonata.media.provider.file
# Upload file as image when sending a file from the image dialog
filebrowserImageUploadRoute: admin_sonata_media_media_ckeditor_upload
filebrowserImageUploadRouteParameters:
provider: sonata.media.provider.image
context: posts # Optional, to upload in a custom context
请说明为什么我的textarea是空的?
答案 0 :(得分:0)
确保添加
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
form:
resources:
# ...
- 'SonataFormatterBundle:Form:formatter.html.twig'
到你的配置文件 (见http://sonata-project.org/bundles/formatter/master/doc/reference/formatter_widget.html)