0

一直试图让债权人在奏鸣曲管理页面上工作,但没有运气。

已按照安装说明进行操作,并认为我已经涵盖了所有内容:

作曲家.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"
},

配置.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 

应用程序/资源/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 文件似乎加载正确,所以一定是配置问题.. .. 有任何想法吗?

4

1 回答 1

1

所有 3 个字段在您的管理类中都是相同的名称,

您应该向您的实体添加 3 个字段format_typeraw_descriptionformatted_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

于 2014-12-09T02:36:57.123 回答