greg-md/php-view
Composer 安装命令:
composer require greg-md/php-view
包简介
A powerful View for PHP.
关键字:
README 文档
README
A powerful View for PHP.
Table of Contents:
Requirements
- PHP Version
^7.1
Compilers
- PHP
- Blade
How It Works
First of all, you have to initialize a Viewer:
$viewsDirectory = __DIR__ . '/views'; $viewer = new \Greg\View\Viewer($viewsDirectory);
Optionally, you can add a view compiler. For example a Blade Compiler specially created for the Viewer:
// Turn it to a callable, to load only when using blade templates. $viewer->addExtension('.blade.php', function () { $compiledViewsDirectory = __DIR__ . '/compiled'; return new \Greg\View\ViewBladeCompiler($compiledViewsDirectory); });
By default it will use Renderer as an instance of a template.
Note: If you want to use your own compiler, it has to be an instance of Compiler Strategy.
Now, you can render views where you want in your application.
Create a template file in the views directory. For example welcome.blade.php:
<html> <body> <h1>Hello, {{ $name }}</h1> </body> </html>
Use welcome template in your application:
$content = $viewer->render('welcome', [ 'name' => 'Greg', ]); echo $content;
Documentation
- Viewer - The view manager;
- Renderer - Instance of a template. Could be accessed via
$thisvariable in the template. - Loader - A special loader for Renderer which will give access only to its public properties and methods;
- Blade Compiler - An independent template compiler;
- View Blade Compiler - An extended Blade Compiler, specially for the Viewer.
- Compiler Strategy - A strategy for custom compilers;
- View Compiler Strategy - A strategy for custom Viewer compilers;
License
MIT © Grigorii Duca
Huuuge Quote
统计信息
- 总下载量: 203
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-15