SonataFormatterBundle 不工作
Posted
技术标签:
【中文标题】SonataFormatterBundle 不工作【英文标题】:SonataFormatterBundle not working 【发布时间】:2015-02-01 08:06:40 【问题描述】:一直试图让债权人在奏鸣曲管理页面上工作,但没有成功。
已按照安装说明进行操作,并认为我已经涵盖了所有内容:
作曲家.json
"require":
"php": ">=5.3.3",
"symfony/symfony": "~2.5",
"doctrine/doctrine-bundle": "~1.2",
"doctrine/data-fixtures": "~1.0",
"doctrine/doctrine-cache-bundle": "~1.0",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"symfony-cmf/symfony-cmf": "1.2.*",
"symfony-cmf/simple-cms-bundle": "1.2.*",
"symfony-cmf/create-bundle": "1.2.*",
"jackalope/jackalope-jackrabbit": "1.1.*",
"sonata-project/doctrine-phpcr-admin-bundle": "~1.2",
"sonata-project/formatter-bundle": "2.3.*@dev",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"nelmio/alice": "~1.0",
"friendsofsymfony/jsrouting-bundle": "@stable"
,
config.yml:
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form:
resources:
- 'SonataFormatterBundle:Form:formatter.html.twig'
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.page.block.children_pages:
sonata.formatter.block.formatter:
sonata_formatter:
formatters:
markdown:
service: sonata.formatter.text.markdown
extensions:
- sonata.formatter.twig.control_flow
- sonata.formatter.twig.gist
#- sonata.media.formatter.twig
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'
sonata_admin:
templates:
# default global templates
layout: SonataAdminBundle::layout.html.twig
app/Resources/SonataAdminBundle/views/layout.html.twig
% extends 'SonataAdminBundle::standard_layout.html.twig' %
% block stylesheets %
parent()
<link rel="stylesheet" href=" asset('bundles/sonataformatter/markitup/skins/sonata/style.css') " type="text/css" media="all" />
<link rel="stylesheet" href=" asset('bundles/sonataformatter/markitup/sets/markdown/style.css') " type="text/css" media="all" />
<link rel="stylesheet" href=" asset('bundles/sonataformatter/markitup/sets/html/style.css') " type="text/css" media="all" />
<link rel="stylesheet" href=" asset('bundles/sonataformatter/markitup/sets/textile/style.css') " type="text/css" media="all" />
% endblock %
% block javascripts %
parent()
<script src=" asset('bundles/ivoryckeditor/ckeditor.js') " type="text/javascript"></script>
<script src=" asset('bundles/sonataformatter/vendor/markitup-markitup/markitup/jquery.markitup.js') " type="text/javascript"></script>
<script src=" asset('bundles/sonataformatter/markitup/sets/markdown/set.js') " type="text/javascript"></script>
<script src=" asset('bundles/sonataformatter/markitup/sets/html/set.js') " type="text/javascript"></script>
<script src=" asset('bundles/sonataformatter/markitup/sets/textile/set.js') " type="text/javascript"></script>
% endblock %
最后是 Admin 类:
protected function configureFormFields(FormMapper $formMapper)
$formMapper
->add('name', 'text', array())
->add('description', 'sonata_formatter_type', array(
'source_field' => 'description',
'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)),
'format_field' => 'description',
'target_field' => 'description',
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher()
))
;
我的管理页面和表单加载正确,但我留下了一个正常(但更大)的文本区域,没有抛出异常,没有 js 错误,并且 js/css 文件似乎加载正确,所以必须是配置问题....有什么想法吗?
【问题讨论】:
【参考方案1】:所有 3 个字段在您的管理类中都同名,
您应该为您的实体添加 3 个字段,format_type、raw_description 和 formatted_description
然后像这样在管理类中更改字段配置:
protected function configureFormFields(FormMapper $formMapper)
$formMapper
->add('name', 'text', array())
->add('format_type', 'sonata_formatter_type', array(
'source_field' => 'raw_description',
'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)),
'format_field' => 'format_type',
'target_field' => 'formatted_description',
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher()
))
;
更多帮助: http://sonata-project.org/bundles/formatter/master/doc/reference/formatter_widget.html#how-to-use-it
【讨论】:
以上是关于SonataFormatterBundle 不工作的主要内容,如果未能解决你的问题,请参考以下文章
马上五十岁了,工作得很不开心,非常郁闷,工作重要还是生活重要?