本文整理汇总了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());
}