Skip to content

Instantly share code, notes, and snippets.

@wilr
Created September 15, 2012 00:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wilr/3725783 to your computer and use it in GitHub Desktop.
Save wilr/3725783 to your computer and use it in GitHub Desktop.
Basic SilverStripe 3.0 Framework Bootstrap
---
Name: app
After: framework/routes#coreroutes
---
Director:
rules:
'dev': 'DevelopmentAdmin'
'sitemap.xml': 'GoogleSitemap'
'$Action' : 'BaseController'
<?php
class BaseController extends Controller {
public static $allowed_actions = array(
'index'
);
/**
* Handle 404 errors gracefully as the normal 404 error pages are part
* of the CMS module
*/
public function handleAction($request) {
try {
$response = parent::handleAction($request);
return $response;
}
catch(SS_HTTPResponse_Exception $e) {
$response = $e->getResponse();
$response->addHeader('Content-Type', 'text/html; charset=utf-8');
$response->setBody($this->renderWith(array('Error', 'BaseController')));
return $response;
}
}
/**
* Return a HTTP error to the user
*/
public function httpError($errorCode = '404', $errorMessage = null) {
$this->response->setStatusCode($errorCode);
return $this->customise(new ArrayData(array(
'Title' => 'Whoops!',
'Content' => DBField::create_field('HTMLText', $errorMessage)
)))->renderWith(array(
'Error',
'BaseController'
));
}
/**
* Home action
*
* @return html
*/
public function index() {
return $this->customise(new ArrayData(array(
'Title' => 'Home',
)))->renderWith(array(
'Home'
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment