PHP code example of fangx / view

1. Go to this page and download the library: Download fangx/view library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fangx / view example snippets




return [
    'engine' => \Fangx\View\HyperfViewEngine::class,
    'mode' => \Hyperf\View\Mode::SYNC,
    'config' => [
        'view_path' => BASE_PATH . '/storage/view/',
        'cache_path' => BASE_PATH . '/runtime/view/',
    ],

    # 自定义组件 @doc https://learnku.com/docs/laravel/7.x/blade/7470#components
    'components' => [
        // 'alert' => \App\View\Components\Alert::class,
    ],

    # 视图命名空间 (通常用于扩展包中)
    'namespaces' => [
        // 'admin' => BASE_PATH . '/storage/view/vendor/admin',
    ],
];


# config/autoload/middlewares.php
return [
    'http' => [
        // ...others
        \Hyperf\Session\Middleware\SessionMiddleware::class, # session
        \Hyperf\Validation\Middleware\ValidationMiddleware::class, # validation
        \Fangx\View\Http\Middleware\ShareErrorsFromSession::class, # 将 session 中的 errors 共享给视图
        \Fangx\View\Http\Middleware\ValidationExceptionHandle::class, # 自动捕捉 validation 中的异常加入到 session 中
    ],
];

# 1. 支持 hyperf 默认的视图渲染方式
# 2. 提供 view() 函数返回
return view('index');

php bin/hyperf.php fangx:view