问题
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.
Something like this:
---
Name: customroutes
After: framework/routes#coreroutes
---
Director:
rules:
'business/???': 'Custom_Controller'
'loans/???': 'Custom_Controller'
回答1:
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
The example shows rendering an rss feed, but this can be adapted to rendering a normal page.
Here's a simplified example:
<?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();
}
}
来源:https://stackoverflow.com/questions/24570107/how-can-i-extend-silverstripe-system-internal-routing