奏鸣曲/交响曲-父/子结构设置 [英] Sonata/symfony - parent/child structure setup

查看:108
本文介绍了奏鸣曲/交响曲-父/子结构设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经问了一段时间了。不敢相信没有一个开发人员不知道答案,而且我有些绝望

I've been asking for this for a while. Can't believe there's not a single dev that wouldn't know the answer and I'm a little desperate

在Sonata中,我无法制作url结构/模式/父级/ ID /子级/列表工作。通过了非常非常差的4.6。在奏鸣曲文档中创建儿童ADMINS部分,仅在网上找到了几个示例,但我无法使其正常工作

In Sonata, I cannot make the url structure/pattern /parent/ID/child/list work. Went thru the very, rather poor, 4.6. CREATE CHILD ADMINS section in sonata docs, found only a few examples online and I can't make it work

有人可以逐步解释如何设置这种结构吗?

Can someone explain step by step how to set such structure up?

推荐答案

我将使用奏鸣曲,在我的解释中,是基本的帖子/评论关系。

I will use the example provided by Sonata in my explanation, a basic Post/Comment relation.

您必须有父母/ child实体(父级)和Comment(子级)之间的/ child链接(oneTomany / manyToOne关系)。

You must have a parent/child link (oneTomany / manyToOne relation) between your entities Post (parent) and Comment (child).

您必须在服务声明中添加参数addChild,该参数以子管理员服务:

You must add in the service declaration the arguments addChild which target the child Admin service:

sonata.news.admin.comment:
    class: Sonata\NewsBundle\Admin\CommentAdmin
    arguments: [~, Sonata\NewsBundle\Model\Comment, SonataNewsBundle:CommentAdmin]
    tags:
        - {name: sonata.admin, manager_type: orm, group: "Content"}
sonata.news.admin.post:
    class: Sonata\NewsBundle\Admin\PostAdmin
    arguments: [~, Sonata\NewsBundle\Model\Post, SonataNewsBundle:PostAdmin]
    tags:
        - {name: sonata.admin, manager_type: orm, group: "Content"}
    calls:
        - [addChild, ['@sonata.news.admin.comment']]

在CommentAdmin类中,您需要添加propertyAssociationMapping来按父级过滤此子级。

In your CommentAdmin class, you need to add the propertyAssociationMapping to filter this child by parent.

class CommentAdmin extends Admin
{
    protected $parentAssociationMapping = 'post';
    ...
}

然后您将有一条新路线可用: / parent / ID / child / list,您可以使用控制台找出新路由的标识符(php app /控制台路由器:调试)。如果您想以一种简单的方式在管理员中访问它,我建议在父管理员列表中添加一个按钮以直接访问其子注释:

Then you will have a new route available: /parent/ID/child/list, you can use the console to figure out the identifier of your new route (php app/console router:debug). If you want an easy way to access this in the admin, i suggest adding a button in the parent Admin list to access directly to its child comments:

创建一个模板,添加按钮以访问孩子的评论:

Create a template which add a button to access to the childs comments:

<a class="btn btn-sm btn-default" href="{{ path('OUR_NEW_CHILD_ROUTE_ID', {'id': object.id }) }}">Comments</a>

然后在这种情况下,在父管理员中添加按钮操作PostAdmin:

Then add the button action in the parent Admin in this case PostAdmin:

class PostAdmin extends Admin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper->add('_action', 'actions', array(
            'actions' => array(
                'show' => array(),
                'edit' => array(),
                'comments' => array('template' => 'PATH_TWIG')
            )
        ))
    }
}

希望您能学到更多设置父母/孩子管理员。

Hope you learned a bit more on how to set parent / child admins.

这篇关于奏鸣曲/交响曲-父/子结构设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆