Merge pull request #279 from limingxinleo/doc

Update view doc.
This commit is contained in:
李铭昕 2019-07-27 14:03:45 +08:00 committed by GitHub
commit c83d15abfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,4 +84,62 @@ class ViewController
```
Hello, Hyperf. You are using blade template now.
```
```
## 视图渲染引擎
官方暂时支持 `Blade``Smarty` 两种模板。
### Blade模板
```
composer require duncan3dc/blade
```
### Smarty模板
```
composer require smarty/smarty
```
### 接入其他模板
创建对应的 `TemplateEngine`,并实现 `Hyperf\View\Engine\EngineInterface` 接口。
```php
<?php
declare(strict_types=1);
namespace App\Engine;
use duncan3dc\Laravel\BladeInstance;
class TemplateEngine implements EngineInterface
{
public function render($template, $data, $config): string
{
$blade = new BladeInstance($config['view_path'], $config['cache_path']);
return $blade->render($template, $data);
}
}
```
然后修改配置
```php
<?php
use App\Engine\TemplateEngine;
return [
'engine' => TemplateEngine::class,
'mode' => Mode::TASK,
'config' => [
'view_path' => BASE_PATH . '/storage/view/',
'cache_path' => BASE_PATH . '/runtime/view/',
],
];
```