我想这是一件很简单的事情。我只想使用RoutingAutoBundle来处理嵌套的页面。
我跟在这里,cms/
假设我有有父级的Page文档。
/**
*
* @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;
}
// ...
}我的自动路由配置如下所示:
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_object提供程序中添加另一个content_object,并调用getParent,但这是行不通的。是否有人熟悉Symfony和RoutingAutoBundle,知道如何做到这一点?文件很少..。
发布于 2014-02-16 22:24:51
您可以使用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: createclass Page
{
// ...
public function getParentPath()
{
return $this->parent instanceof static ? $this->parent->getTitle() : null;
}
}您也可以使用content_object,但计划将其从包中删除。
https://stackoverflow.com/questions/21816591
复制相似问题