Symfony 生成在SonatAdmin中显示phpcr文档版本的自定义url时出错

Symfony 生成在SonatAdmin中显示phpcr文档版本的自定义url时出错,symfony,sonata-admin,symfony-cmf,doctrine-phpcr,Symfony,Sonata Admin,Symfony Cmf,Doctrine Phpcr,因此,我试图扩展SonataAdmin show视图,以获得文档版本的列表(phpcr检查点或签入) 我已经正确显示了保存的版本列表,现在我需要将它们制作成显示该版本内容的链接,但在尝试添加自定义路由时,我遇到以下错误: An exception has been thrown during the rendering of a template ("Parameter "id" for route "admin_cmsbundle_product_show_version" must ma

因此,我试图扩展SonataAdmin show视图,以获得文档版本的列表(phpcr检查点或签入)

我已经正确显示了保存的版本列表,现在我需要将它们制作成显示该版本内容的链接,但在尝试添加自定义路由时,我遇到以下错误:

An exception has been thrown during the rendering of a template 
("Parameter "id" for route "admin_cmsbundle_product_show_version" must 
match "[^/]++" ("mstr/product/product-253562" given) to generate a 
corresponding URL.") in CmsBundle:product:show.html.twig at line 18.
这是我的管理类中的配置路由:

protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('show_version', $this->getRouterIdParameter() . '/show/{version}');
}
这是我的覆盖模板:

{% block show %}

<ul>
    {% for version in versions %}
        <li><a href="{{  admin.generateObjectUrl('show_version', object, {'version': version.name}) }}">Version: {{ version.name }} </a></li>
    {% endfor %}
</ul>

{{ parent() }}    
这是我在控制器中的showVersion操作:

public function showVersionAction($id = null, $version = "1.0")
{ 
    ...
    return $this->render($this->admin->getTemplate('show'), array(
        'action'   => 'show',
        'object'   => $this->getVersion($object, $version),
        'elements' => $this->admin->getShow(),
        'versions' => $this->getVersionHistory($object)
    ));
}
注意,generateUrl给出了相同的错误:

<a href="{{  admin.generateUrl('show_version', {'id': object.id, 'version': version.name}) }}">Version: {{ version.name }} </a>

我做错了什么


如果您有任何关于修复此问题的帮助,我们将不胜感激:)

根据错误消息,
$object
存在一些问题。因此,可以使用
generateUrl
而不是
generateObjectUrl()
并在数组中传递您的id:

{% block show %}

<ul>
    {% for version in versions %}
        <li><a href="{{  admin.generateUrl('show_version', {'id':object.id,'version': version.name}) }}">Version: {{ version.name }} </a></li>
    {% endfor %}
</ul>

{{ parent() }}
{% endblock %}
{%block show%}
    {版本%中的版本为%1}
  • {%endfor%}
{{parent()}} {%endblock%}
仔细研究了一下,答案很简单,只需覆盖id的模式即可+

protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('show_version', $this->getRouterIdParameter() . '/show/{version}', array(), array('id' => '.+'));
}

我试过了,并给出了相同的错误,它只是不喜欢对象id为mstr/product/product-253562,我猜它应该是一个整数。所以检查你的管理路由名称。从CLI:
app/console sonata:admin:explain/path/to/your/object/without/id/和/show
然后将其放入configureRoutes:protected函数configureRoutes(RouteCollection$collection){$collection->add('show_version',the_name_From_admin_explain./{id}/show/{version})}
protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('show_version', $this->getRouterIdParameter() . '/show/{version}', array(), array('id' => '.+'));
}