public
Last active

Basic SilverStripe 3.0 Framework Bootstrap

  • Download Gist
app._config.routes.yml
YAML
1 2 3 4 5 6 7 8 9
---
Name: app
After: framework/routes#coreroutes
---
Director:
rules:
'dev': 'DevelopmentAdmin'
'sitemap.xml': 'GoogleSitemap'
'$Action' : 'BaseController'
app.code.controllers.BaseController.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?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'
));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.