本文介绍了我如何扩展SilverStripe的“系统/内部”功能?路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些树状页面,例如:
I have some tree pages like:
/business
/loans
/personal
/bad-credit
etc.
如何扩展内部/框架路线(无创建子页面)以获取链接,例如:
How can extend internal/framework routes (without creating child pages) to get links like:
/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'
推荐答案
您不需要自定义路由-您只需要按以下说明向页面控制器添加allowed_actions:
You don't need custom routing - you just need to add an allowed_actions to your page controller as described here: http://doc.silverstripe.com/framework/en/tutorials/2-extending-a-basic-site#creating-a-rss-feed
该示例显示了渲染rss feed,
The example shows rendering an rss feed, but this can be adapted to rendering a normal page.
这是一个简化的示例:
<?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();
}
}
这篇关于我如何扩展SilverStripe的“系统/内部”功能?路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!