本文整理匯總了PHP中Slim::root方法的典型用法代碼示例。如果您正苦於以下問題:PHP Slim::root方法的具體用法?PHP Slim::root怎麽用?PHP Slim::root使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Slim
的用法示例。
在下文中一共展示了Slim::root方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetRoot
/**
* 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
}
示例2: render
/**
* 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);
}
示例3: testRootPathInSubDirectory
/**
* 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());
}