我有一些树形图:
/business
/loans
/personal
/bad-credit
etc.
如何扩展内部/框架路由(不创建子页面)以获取如下链接:
/business/segment
/loans/some-segment
/personal/some-another-segment
/bad-credit/awesome-segment
etc.
这样的事情:
---
Name: customroutes
After: framework/routes#coreroutes
---
Director:
rules:
'business/???': 'Custom_Controller'
'loans/???': 'Custom_Controller'
答案 0 :(得分:4)
您不需要自定义路由 - 您只需要在页面控制器中添加allowed_actions,如下所述:http://doc.silverstripe.com/framework/en/tutorials/2-extending-a-basic-site#creating-a-rss-feed
该示例显示了呈现rss提要,但这可以适用于呈现正常页面。
这是一个简化的例子:
<?php
class MyPage extends Page {
}
class MyPage_Controller extends Page_Controller {
private static $allowed_actions = array(
"segment",
);
// URL: domain.com/page-url/segment
public function segment() {
// By default this will look for the template MyPage_segment.ss
// If that's not found, it will fall back to MyPage.ss
// Then Page.ss and so on...
return $this->render();
}
}