2014-07-04 42 views
1

我有些樹的網頁,如:如何擴展SilverStripe「系統/內部」路由?

/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' 

回答

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(); 
    } 

} 
+0

謝謝!但是動態允許的操作呢? –

+0

這個頁面應該有幫助:http://doc.silverstripe.org/framework/en/topics/controller – micmania1