fangx / view
此包已被废弃,不再维护。作者建议使用 hyperf/view-engine 包。
v1.0.4
2020-09-04 08:19 UTC
Requires
- php: ^7.2.0
- ext-json: *
- hyperf/config: ^2.0
- hyperf/di: ^2.0
- hyperf/event: ^2.0
- hyperf/session: ^2.0
- hyperf/translation: ^2.0
- hyperf/utils: ^2.0
- hyperf/validation: ^2.0
- hyperf/view: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12
- phpunit/phpunit: *
- psr/http-message: ^1.0
README
安装
通过 Composer
composer require fangx/view
配置
生成配置文件,此命令会覆盖 config/autoload/view.php
文件
php bin/hyperf.php fangx:view
此命令会自动发布
hyperf/session
/hyperf/validation
/hyperf/translation
三个组件的配置文件,如需覆盖已存在的配置,请添加-f
参数
内容如下
<?php 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');