violet88/silverstripe-react-bridge
Composer 安装命令:
composer require violet88/silverstripe-react-bridge
包简介
A Silverstripe module to make it easy to render React into the Silverstripe CMS.
关键字:
README 文档
README
This module takes care of rendering custom React form fields in the Silverstripe CMS. This is useful for the parts in the CMS that are not built in React.
Installation
composer install violet88/silverstripe-react-bridge
Usage
1. Create a React component
Create a React component for your custom field. The module will pass the following props to your component:
name: The name of the fieldvalue: The value of the fieldonAutofill: The function to which you should pass the new value of the field, as well as the name of the field. This will update the value of the field in the CMS. You can pass the new value as follows
onAutofill(name, value)
2. Register the React component
Register your React component by calling the registerMany function from SilverStripe's lib/Injector:
import Injector from 'lib/Injector'; import SecretField from "./SecretField"; Injector.component.registerMany({ SecretField });
I would advise to make a specific javascript file for registering your components, and include it in your project. I personally put this in a boot folder. It would look something like this:
import Injector from 'lib/Injector'; import SecretField from "../SecretField"; export default () => { Injector.component.registerMany({ SecretField }); };
After that I would use this file in your main.js file like this:
/* global window */ import registerComponents from 'boot/registerComponents'; window.document.addEventListener('DOMContentLoaded', () => { registerComponents(); });
3. Add javascript to the CMS
Add the javascript file to the CMS. You can do this by adding the following to your config.yml:
SilverStripe\Admin\LeftAndMain: extra_requirements_javascript: - 'app/client/dist/js/bundle.js'
You have to replace 'app/client/dist/js/bundle.js' with the path to your compiled javascript file.
4. Create a PHP class for your custom field
Now we will create a PHP class for our custom field. This class will extend ReactFormField. It would work like any other form field in Silverstripe. You can add your own logic to this class. For example, you can add validation or custom logic to the field. The only difference is, you will pass it a React component name
<?php use Violet88\SilverstripeReactBridge\ReactFormField; class MySecretFormField extends ReactFormField { public function __construct($name, $title = null, $value = null) { parent::__construct($name, 'SecretField', $title, $value); } }
In this case 'SecretField' (the second parameter passed to the parent constructor) is the name of the React component we registered in step 2.
5. Use the custom field in your form
You can now use your custom field in your form like any other form field. For example:
$fields->addFieldToTab('Root.Main', MySecretFormField::create('SecretField', 'Secret Field'));
violet88/silverstripe-react-bridge 适用场景与选型建议
violet88/silverstripe-react-bridge 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「silverstripe」 「react」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 violet88/silverstripe-react-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 violet88/silverstripe-react-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 violet88/silverstripe-react-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Async Reactive Postgres Driver for PHP (Non-blocking)
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Analytics chooser extensions for site settings.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-09-03