21489 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 877 Views |
-
Custom 404 message (ErrorPage)

25 December 2010 at 3:47am
For a SilverStripe website we're currently working on, we've been making use of the "httpError" method for redirecting users to the 404 page when e.g. a DataObject cannot be found on a certain page. Everything is set up properly; there is an instance of ErrorPage in the Site Tree, I've added an ErrorPage.ss file to the Layout directory of our theme and it is being displayed properly whenever it is supposed to. There's just one thing that has us stumped.
According to the SS Docs, the httpError method can take two arguments:
We're assuming that $message is for sending a custom message along to the ErrorPage template. But we can't figure out how to display this message and I haven't had any luck searching the forum, the Docs and Google looking for an example.void httpError( $code, [ $message = null])
The reason why we want to do this, is because that way we can use the same template but display a different (sub-)message depending on what the user was trying to access. For example:
return $this->httpError(404, 'Sorry, the portfolio item you are looking for could not be found.');
return $this->httpError(404, 'Sorry, the member you are looking for does not exist.');
Is the reason that I can't seem to display the message in the template because it is only for logging purposes maybe? -
Re: Custom 404 message (ErrorPage)

21 July 2012 at 2:40am
mmm. i would also like to know. probably need to put a tag in the Errorpage type??
-
Re: Custom 404 message (ErrorPage)

29 March 2013 at 10:36am
I also had this problem today - here is the solution I came up with - all it does is presents the current page but with the content and or title overridden and the response code changed. This example uses 404 but you could easily modify the function to accept a different code as an argument.
In Page_Controller
public function Custom404($content=false,$title=false) {
if ($content) $this->Content = $content;
if ($title) $this->Title = $title;
$response = new SS_HTTPResponse($this->RenderWith('Page'),404);
$response->output();
exit; //Maybe not necessary but doesn't hurt
}In your code (assuming $this refers to a page)
$this->Custom404("<h2>Error - Page not found</h2><p>Your session may have expired - Please try again</p>");
-
Re: Custom 404 message (ErrorPage)

29 March 2013 at 10:37am
p.s. this is for 2.4 - don't know if it works for SS3
| 877 Views | ||
|
Page:
1
|
Go to Top |



