leafs / inertia
Leaf PHP适配器用于Inertia.js
v0.1.0
2023-08-11 20:48 UTC
Requires
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
README
Leaf + Inertia
这是一个简单的包,帮助您使用Inertia.js和Leaf。它提供了一个Inertia类,使得从Leaf控制器返回Inertia响应和从Leaf视图输出Inertia模板变得容易。
由于Leaf支持多种模板引擎,inertia使用您在视图配置中配置的引擎。
安装
注意:在Leaf MVC中已为您完成此操作。
由于这是Leaf的服务器端适配器,您需要在客户端使用您正在使用的框架安装Inertia。您可以在Inertia网站上找到列表。
npm install @inertiajs/react
之后,您可以使用Leaf CLI将Leaf适配器添加到项目中
leaf install inertia
或使用composer
composer require leafs/inertia
用法
要开始,您需要将Leaf视图替换为Inertia组件。用Inertia::render方法代替默认的Leaf视图。此方法接受组件的名称作为第一个参数,以及作为第二个参数的数据数组
app()->get('/', function() { return Inertia::render('Home', [ 'name' => 'Leaf' ]); });
关于leaf的完整文档请参阅leaf文档。