2014-02-16 200 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