首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用RoutingAutoBundle (Symfony CMF)的嵌套路由

使用RoutingAutoBundle (Symfony CMF)的嵌套路由
EN

Stack Overflow用户
提问于 2014-02-16 21:04:19
回答 1查看 634关注 0票数 1

我想这是一件很简单的事情。我只想使用RoutingAutoBundle来处理嵌套的页面。

我跟在这里,cms/

假设我有有父级的Page文档。

代码语言:javascript
复制
/**
 * 
 * @PHPCR\Document(referenceable=true)
 * 
 * @author Matt Durak <mattdurak@gmail.com>
 */
class Page implements RouteReferrersReadInterface
{
    /**
     * @PHPCR\Id()
     */
    protected $id;

    /**
     * @PHPCR\ParentDocument()
     */
    protected $parent;

    //...

    /**
     * Get ID
     * 
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    public function getParent()
    {
        return $this->parent;
    }

    public function setParent($parent)
    {
        $this->parent = $parent;

        return $this;
    }

    // ...
}

我的自动路由配置如下所示:

代码语言:javascript
复制
cmf_routing_auto:
    mappings:
        Study\MainBundle\Document\Page:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: auto_increment
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create

我想要下面这样的东西。假设我有这样的数据:

代码语言:javascript
复制
/cms/pages
     /page-1
     /page-2
         /page-A
         /page-B

目前,这4页将有以下路线

代码语言:javascript
复制
/page/page-1
/page/page-2
/page/page-A
/page/page-B

我想要

代码语言:javascript
复制
/page/page-1
/page/page-2
/page/page-2/page-A
/page/page-2/page-B

我尝试过在content_object提供程序中添加另一个content_object,并调用getParent,但这是行不通的。是否有人熟悉Symfony和RoutingAutoBundle,知道如何做到这一点?文件很少..。

EN

回答 1

Stack Overflow用户

发布于 2014-02-16 22:24:51

您可以使用content_method提供程序并在类中返回null或父提供程序。对于RoutingAutoBundle alpha10,允许提供程序不向路径添加任何内容。

代码看起来应该是:

代码语言:javascript
复制
cmf_routing_auto:
    mappings:
        Study\MainBundle\Document\Page:
            content_path:
                pages:
                    provider: [specified, { path: /cms/routes/page }]
                    exists_action: auto_increment
                    not_exists_action: create
                parent:
                    provider: [content_method, { method: getParentPath }]
                    exists_action: use
                    not_exists_action: create
            content_name:
                provider: [content_method, { method: getTitle }]
                exists_action: auto_increment
                not_exists_action: create
代码语言:javascript
复制
class Page
{
    // ...

    public function getParentPath()
    {
        return $this->parent instanceof static ? $this->parent->getTitle() : null;
    }
}

您也可以使用content_object,但计划将其从包中删除。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21816591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档