2014-02-16 114 views
1

我想这是一个足够简单的事情。我只想使用RoutingAutoBundle为嵌套页面。RoutingAutoBundle嵌套路由(Symfony CMF)

我一起在这里以下http://symfony.com/doc/current/cmf/cookbook/creating_a_cms/

说我有这有一个父Page文件。

/** 
* 
* @PHPCR\Document(referenceable=true) 
* 
* @author Matt Durak <[email protected]> 
*/ 
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; 
    } 

    // ... 
} 

我的自动路由配置是像这样:

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 

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

/cms/pages 
    /page-1 
    /page-2 
     /page-A 
     /page-B 

目前,这4页将有以下途径

/page/page-1 
/page/page-2 
/page/page-A 
/page/page-B 

我想

/page/page-1 
/page/page-2 
/page/page-2/page-A 
/page/page-2/page-B 

我已经尝试添加另一个content_pathcontent_object供应商,并呼吁getParent,但没有奏效。有谁熟悉Symfony CMF和RoutingAutoBundle知道如何做到这一点?文档很稀疏...

+0

网址应该如何显示? (顺便说一句,这个软件包是完整的文档,它仍然处于测试阶段,所以它缺少一些提示和技巧) –

+0

添加了我看到的路线和我想要的路线。是的,文档缺少超出基础的有用示例。这将是非常有用的 – Matt

回答

1

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

的代码是这样:

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 
class Page 
{ 
    // ... 

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

你也可以使用content_object,而是一个计划从包中移除。

+0

'null'似乎不起作用。如果我返回一个空字符串,它说这是不允许的。 “注意:未定义的变量:在D:\ web_workspace \ study \ vendor \ symfony-cmf \ routing-auto-bundle \ Symfony \ Cmf \ Bundle \ R中的对象outingAutoBundle \ AutoRoute \ PathProvider \ ContentMethodProvider.php on line 82” – Matt