【问题标题】:SilverStripe 3.1+ Dynamically creating page redirectsSilverStripe 3.1+ 动态创建页面重定向
【发布时间】:2016-04-29 20:48:56
【问题描述】:

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

/ProductPageUrlSegment/?tab=video

/ProductPageUrlSegment/?tab=audio

/ProductPageUrlSegment/?tab=photos

我希望在创建每个新产品页面时创建重定向,这样如果您导航 /ProductPageUrlSegment/video,它会转到 /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/

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

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

我的会是这样的:

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

我不具备解决此问题的知识,因此感谢任何指导。

【问题讨论】:

    标签: php redirect url-rewriting silverstripe


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复!不幸的是,我收到此错误:“尝试打开页面时发生了太多重定向”该页面也立即尝试转到“/?tab = video”它只需要转到产品 URL,然后标签可以是导航并仅在输入 /videos 等时重定向。
    • 您的答案适用于其他页面,但不适用于我的产品页面,所以我必须有一些东西阻止它工作......我接受了你的答案,因为它确实有效。
    • 原来我的案例中的一个动作“视频”与我的 $has_many 关系和 GridFields 之一匹配,并且似乎冲突,重命名该动作使其一切正常,或者我想我可以改变关系.
    猜你喜欢
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    • 2018-01-30
    相关资源
    最近更新 更多