humble / view
HUMBLE View
dev-master
2016-10-18 13:25 UTC
Requires
- php: >=7.0.0
- humble/standards: ~1.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ~5.2
This package is not auto-updated.
Last update: 2024-09-14 19:04:00 UTC
README
HUMBLE View
安装
通过 Composer
$ composer require humble/view
用法
获取 Php 视图。
$view = new \Humble\View\View;
设置模板路径。
$view->setTemplatePath('/absolute/path/to/templates/');
设置布局。
$view->setLayout('relative/path/to/layout.php');
使用预设设置获取 Php 视图。
$view = new \Humble\View\View([
'templatePath' => '/absolute/path/to/templates/',
'layout' => 'relative/path/to/layout.php',
]);
注册扩展。
$extension = new Extension
$view->register('extensionName', $extension);
注册回调。
$callback = function(string $string) { return strtoupper($string); };
$view->register('callableName', $callback);
获取已注册扩展。
$view->get('extensionName');
获取已注册的可调用扩展或回调。
$view->call('callableName', 'string');
使用布局部分渲染 PSR-7 响应。
$view->render(new Response(), array('section' => 'relative/path/to/section.php'));
使用布局部分和视图数据渲染 PSR-7 响应。
$view->render(new Response(), [
'header' => 'relative/path/to/header.php',
'content' => 'relative/path/to/content.php',
], [
'data' => array(),
]);
获取布局输出。
$view->layout('relative/path/to/layout/default.php', [
'section' => 'relative/path/to/section.php',
], [
'data' => array(),
]);
获取局部输出。
$view->partial('relative/path/to/partial.php', [
'data' => array(),
]);
获取模板的绝对路径。
$view->getTemplate('relative/path/to/template.php');
在布局中使用部分。
<?= $section->header; ?>
<?= $section->content; ?>
在布局或部分中使用视图数据。
<?= $view->data; ?>
在布局、部分或局部中使用扩展。
<?= $this->get('extensionName'); ?>
在布局、部分或局部中使用可调用函数。
<?= $this->call('callableName', 'string'); ?>
在其他布局、部分或局部中包含布局。
<?= $this->layout('relative/path/to/layout.php', [
'section' => 'relative/path/to/section.php'
]); ?>
在布局、部分或其他部分中包含部分。
<?= $this->partial('relative/path/to/partial.php'); ?>
许可证
MIT 许可证(MIT)。请参阅许可证文件获取更多信息。