Swoole frame Hyperf (V) - View

Installation required

# composer require hyperf/view
# composer require hyperf/task
# composer require duncan3dc/blade

In config/autoload/case created view.phpas a profile view

<?php
declare(strict_types=1);

use Hyperf\View\Mode;
use Hyperf\View\Engine\BladeEngine;

return [
    // 使用的渲染引擎
    'engine' => BladeEngine::class,
    // 不填写则默认为 Task 模式,推荐使用 Task 模式
    'mode' => Mode::TASK,
    'config' => [
        // 若下列文件夹不存在请自行创建
        'view_path' => BASE_PATH . '/storage/view/', // 模版文件路径
        'cache_path' => BASE_PATH . '/runtime/view/', // 模版缓存路径
    ],
];

If a profile is not the path, you create a new folder
Here Insert Picture Description
profile new
Here Insert Picture Description

<?php

declare(strict_types=1);

use Hyperf\Server\SwooleEvent;

return [
    // 这里省略了其它不相关的配置项
    'settings' => [
        // Task Worker 数量,根据您的服务器配置而配置适当的数量
        'task_worker_num' => 8,
        // 因为 `Task` 主要处理无法协程化的方法,所以这里推荐设为 `false`,避免协程下出现数据混淆的情况
        'task_enable_coroutine' => false,
    ],
    'callbacks' => [
        // Task callbacks
        SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
        SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
    ],
];

New index.blade.php
Here Insert Picture Description

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hyperf</title>
</head>
<body>
Hello, {{ $name }}. ni hao niu bi o.
</body>
</html>

Access
Here Insert Picture Description
template file just in /storage/view/case he can easily build a catalog distinction
Here Insert Picture Description
focuses name when rendering
Here Insert Picture Description

Published 112 original articles · won praise 75 · views 130 000 +

Guess you like

Origin blog.csdn.net/weikaixxxxxx/article/details/98316566