amgrade / bifrost
PHP和JS变量之间的桥梁
dev-main
2023-11-07 03:59 UTC
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-09-07 05:58:23 UTC
README
此包的开发旨在作为PHP和JavaScript之间的桥梁。
安装
composer require amgrade/bifrost
使用
// Somewhere in your controller class. \AMgrade\Bifrost\Bifrost::push(['foo' => 'bar', 'baz' => 'foo']);
// Later in your view (e.g. Laravel Blade). <head> ... {!! \AMgrade\Bifrost\Bifrost::toHtml() !!} </head>
// In your JS app. console.log(window.Bifrost.foo); console.log(window.Bifrost.baz);
配置
您可以通过传递自己的命名空间来防止名称冲突。
<head> ... {!! \AMgrade\Bifrost\Bifrost::toHtml('YOUR_NAMESPACE') !!} </head>
// In your JS app. console.log(window.YOUR_NAMESPACE.foo); console.log(window.YOUR_NAMESPACE.baz);