Skip to content

Instantly share code, notes, and snippets.

@patricknelson
Last active August 29, 2015 14:21
Show Gist options
  • Save patricknelson/891ce9a8f5fc79894f9b to your computer and use it in GitHub Desktop.
Save patricknelson/891ce9a8f5fc79894f9b to your computer and use it in GitHub Desktop.
Access SilverStripe framework outside of typical page controller. Rapid prototyping.
<?php
/**
* Include this file if you wish to tie into the SilverStripe framework to test your code in a separate workbench area
* without having to build a page controller, data object and then go through the full request cycle. This is good for
* rapid prototyping before rolling out any sort of final code. NOTE: This *is* suitable for use in the command line as
* well.
*
* @author Patrick Nelson, pat@catchyour.com
* @since 2015-01-06
*/
// General initialization.
global $databaseConfig;
chdir(__DIR__ . "/../framework");
require_once("core/Core.php");
require_once("model/DB.php");
DB::connect($databaseConfig);
DataModel::set_inst(new DataModel());
// For command line.
if (php_sapi_name() == "cli") {
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
$_SERVER['REQUEST_URI'] = BASE_URL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment