Silverstripe 3:我可以在 silverstripe 中为某些页面类型设置自定义错误页面吗? [英] Silverstripe 3: Can I set a custom error page in silverstripe for certain page types?

查看:56
本文介绍了Silverstripe 3:我可以在 silverstripe 中为某些页面类型设置自定义错误页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 Silverstripe 上为特定页面类型设置自定义 404 页面,而所有其他 404 错误都使用默认页面.

I'm wondering if it is possible to set a custom 404 page on silverstripe specific to a certain page type, while all other 404 errors use the default one.

我有一个特定的页面类型事件",其中的事件页面在特定日期之后未发布.

I have a particular page type "Events" which has event pages unpublished after their specific date.

我还有一个静态页面,其中包含指向某些事件的链接.此页面 url 被发送给成员,因此即使在某些事件可能已经过去之后,他们仍然可以访问该页面.

I also have a static page with links to some of the events. This page url is sent to members so they will still have access to the page even after some of the events may have passed.

一旦事件过去,它就会取消发布,因此点击链接将导致 404 错误页面.该链接仍将在静态页面上可用.

Once an event has passed, it is unpublished and therefore following the link will lead to a 404 error page. The link will still be available on the static page.

我想为事件页面类型设置一个特定的错误页面,这样当有人点击过去事件的链接时,他们会看到错误页面 A.此事件已经过去,转到我们的事件页面"

I am wanting to set a specific error page for the Event page type so that when someone follows the link to a past event they will get error page A. "this event has passed, go to our events page"

然后我想要一个常规错误页面 B找不到页面,转到我们的主页",它将是站点上任何其他错误链接的错误页面.

I then want a regular error page B "page not found, go to our home page" that will be the error page for any other incorrect links on the site.

有什么办法可以做到这一点??我正在使用silverstripe 3

Is there any way I can do this?? I am using silverstripe 3

推荐答案

适用于任何遇到此问题的人的解决方案:

Solution for anyone who comes across this:

config.yml

RequestHandler:
  extensions:
    - ExpiredEventRedirectExtension

ContentController:
  extensions:
    - ExpiredEventRedirectExtension

ModelAsController:
  extensions:
    - ExpiredEventRedirectExtension

ExpiredEventRedirectExtension.php

public function onBeforeHTTPError404($request)
{
    $urlSegment = $request->param('URLSegment');

    if ($urlSegment == "events") {
        $response = new SS_HTTPResponse();
        $response->redirect("/event-no-longer-available/");
    } 

    throw new SS_HTTPResponse_Exception($response);
}

如果事件已列在事件"EventHolder 页面类型下方,则这会将用户重定向到事件"页面类型的不再可用事件"页面.如果它不是来自这个 URL,一个常规的 404 错误页面将显示

This redirects the user to event-no-longer-available which is of page type "Page" if the event has been listed below the "events" EventHolder page type. If it hasn't come from this URL a regular 404 error page will show

这篇关于Silverstripe 3:我可以在 silverstripe 中为某些页面类型设置自定义错误页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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