How can I extend SilverStripe “system/internal” routing?

左心房为你撑大大i 提交于 2019-12-11 14:33:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!