Created
September 15, 2012 00:29
-
-
Save wilr/3725783 to your computer and use it in GitHub Desktop.
Basic SilverStripe 3.0 Framework Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
Name: app | |
After: framework/routes#coreroutes | |
--- | |
Director: | |
rules: | |
'dev': 'DevelopmentAdmin' | |
'sitemap.xml': 'GoogleSitemap' | |
'$Action' : 'BaseController' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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