/** * Test get filesystem path to Slim app root directory */ public function testGetRoot() { $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); //<-- No trailing slash $s = new Slim(); $this->assertEquals($_SERVER['DOCUMENT_ROOT'] . '/foo/', $s->root()); //<-- Appends physical app path with trailing slash }
/** * Render a template * * Call this method within a GET, POST, PUT, DELETE, or NOT FOUND * callback to render a template, whose output is appended to the * current HTTP response body. How the template is rendered is * delegated to the current View. * * @param string $template The name of the template passed into the View::render method * @param array $data Associative array of data passed for the View * @param int $status The HTTP response status code to use (Optional) */ public static function render($template, $data = array(), $status = null) { //TODO: Abstract setting the templates directory into Slim::set('templates', '/path') in Phase 3 self::view()->templatesDirectory(Slim::root() . 'templates'); if (!is_null($status)) { self::response()->status($status); } self::view()->data($data); self::view()->render($template); }
/** * Test Slim Root From Subdirectory * * Pre-conditions: * Slim app instantiated; * Slim app installed in a physical, public subdirectory of document root; * * Post-conditions: * Slim correctly reports root path; */ public function testRootPathInSubDirectory() { $_SERVER['REQUEST_URI'] = '/foo/bar'; $_SERVER['SCRIPT_NAME'] = '/foo/bootstrap.php'; $_SERVER['PHP_SELF'] = '/foo/bootstrap.php'; $rootPath = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/foo/'; $app = new Slim(); $this->assertEquals($rootPath, $app->root()); }