Symfony 2 Sonata Admin Bundle 的表演动作不起作用

The show action of Symfony 2 Sonata Admin Bundle is not working

我正在整合 Sonata Admin Bundle into my Symfony 2.6 application by following Symfony 2 jobeet tutorial. Everything is fine except the Show action。我有一个完整的"Job",所以我有src/Ibw/JobeetBundle/Admin/JobAdmin.php,它有一个函数configurShowField(ShowMapper $showMapper),如下所示

<?php
namespace Ibw\JobeetBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;

use Ibw\JobeetBundle\Entity\Job;

class JobAdmin extends Admin
{
    // ....

    protected function configureShowField(ShowMapper $showMapper)
    {
        $showMapper
            ->add('category')
            ->add('type')
            ->add('company')
            ->add('webPath', 'string', array('template' => 'IbwJobeetBundle:JobAdmin:list_image.html.twig'))
            ->add('url')
            ->add('position')
            ->add('location')
            ->add('description')
            ->add('how_to_apply')
            ->add('is_public')
            ->add('is_activated')
            ->add('token')
            ->add('email')
            ->add('expires_at')
        ;
    }

    // ....
}

当我单击“显示”按钮并转到查看页面 (admin/ibw/jobeet/job/xxx/show) 时,它会显示 none 个字段。处理后的原模板为/vendor/sonata-project/admin-bundle/Resources/views/CRUD/base_show.html.twig:

{% extends base_template %}

{% block actions %}
    <li>{% include 'SonataAdminBundle:Button:edit_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:history_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:list_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:create_button.html.twig' %}</li>
{% endblock %}

{% block tab_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active', 'template': admin_pool.getTemplate('tab_menu_template')}, 'twig') }}{% endblock %}

{% block show %}
    <div class="sonata-ba-view">
        ***
        {{ sonata_block_render_event('sonata.admin.show.top', { 'admin': admin, 'object': object }) }}

        {% for name, view_group in admin.showgroups %}
            <table class="table table-bordered">
                {% if name %}
                    <thead>
                        {% block show_title %}
                            <tr class="sonata-ba-view-title">
                                <th colspan="2">
                                    {{ admin.trans(name) }}
                                </th>
                            </tr>
                        {% endblock %}
                    </thead>
                {% endif %}

                <tbody>
                    {% for field_name in view_group.fields %}
                        {% block show_field %}
                            <tr class="sonata-ba-view-container">
                                {% if elements[field_name] is defined %}
                                    {{ elements[field_name]|render_view_element(object) }}
                                {% endif %}
                            </tr>
                        {% endblock %}
                    {% endfor %}
                </tbody>
            </table>
        {% endfor %}

        {{ sonata_block_render_event('sonata.admin.show.bottom', { 'admin': admin, 'object': object }) }}

    </div>
{% endblock %}

除了我打印的三个星号外,<div class="sonata-ba-view"></div>的内容没有显示出来。我缺少任何配置吗?

尝试在您的 admin.yml

中添加呼叫
ibw_jobbeet.admin.jobadmin:
    class: Ibw\JobeetBundle\Admin\JobAdmin
    ...
    calls:
        - [ setTemplate, ['show', path_to_your_view.html.twig]]

Read more about templates in SonataAdmin

您的函数名称中缺少一个 s。

configureShowFields(FormMapper $formMapper)

不是

configureShowField(FormMapper $formMapper)