SilverStripe 3.1+ 动态创建页面重定向 [英] SilverStripe 3.1+ Dynamically creating page redirects

查看:57
本文介绍了SilverStripe 3.1+ 动态创建页面重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面类型ProductPage",它有导航到这样的标签:

I have a page type 'ProductPage', it has tabs that are navigated to like so:

/ProductPageUrlSegment/?tab=video

/ProductPageUrlSegment/?tab=video

/ProductPageUrlSegment/?tab=audio

/ProductPageUrlSegment/?tab=audio

/ProductPageUrlSegment/?tab=photos

/ProductPageUrlSegment/?tab=photos

我希望在创建每个新产品页面时创建重定向,这样如果您导航 /ProductPageUrlSegment/video,它就会转到 /ProductPageUrlSegment/?tab=video强>

I'd like for redirects to be created when each new product page is created so that if you navigated /ProductPageUrlSegment/video it goes to /ProductPageUrlSegment/?tab=video

并且所有选项卡都相同.我不清楚是否应该使用路由 https://docs.silverstripe.org/en/3.3/developer_guides/controllers/routing/ 或重定向https://docs.silverstripe.org/en/3.3/developer_guides/controllers/redirection/

and the same for all tabs. I'm not clear if I should be using Routing https://docs.silverstripe.org/en/3.3/developer_guides/controllers/routing/ or redirection https://docs.silverstripe.org/en/3.3/developer_guides/controllers/redirection/

我有另一个项目的链接功能,可以转到父页面

I have a link function for another project which goes to the parent page

public function Link() {
    return $this->Parent()->Link() . '#' . $this->URLSegment;
}

我的应该是这样的:

public function LinkVideo() {
    return $this->Link()->'/?=video' . '#' . $this->URLSegment->'/video';
}

我没有解决此问题的知识,因此感谢任何指导.

I don't have the knowledge to work this out so any guidance appreciated.

推荐答案

这将实现上述目的,将 URL 作为操作处理,然后重定向到同一页面,但设置了 get 变量...

This will achieve the above, by handling the URL as an action and then redirecting to the same page, but with the get variable set...

class ProductPage extends Page {

}

class ProductPage_Controller extends Page_Controller {

    private static $allowed_actions = array(
        'video',
        'audio',
        'photos',
    );

    public function video() {
         $this->redirect($this->Link().'?tab=video');
    }
    public function audio() {
        $this->redirect($this->Link().'?tab=audio');
    }
    public function photos() {
        $this->redirect($this->Link().'?tab=photos');
    }
}

这篇关于SilverStripe 3.1+ 动态创建页面重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆