rnr1721/le7-jsenv
最新稳定版本:1.0.4
Composer 安装命令:
composer require rnr1721/le7-jsenv
包简介
JS variable environment for le7 PHP MVC framework or any PHP project
README 文档
README
JS variable environment for le7 PHP MVC framework or any PHP project
This is simple classes for transfer some data to Javascript, such as API addresses, AJAX callback URLs etc.
Requirements
- PHP 8.1 or higher.
- Composer 2.0 or higher.
What it can?
- Transfer data from PHP to JS as constants
- Store data type as possible - bool, int, float, string (array will be converted to string JSON)
Installation
composer require rnr1721/le7-jsenv
Testing
composer test
How it works?
use Core\Factories\JsEnvFactory; $jsEnvFactory = new JsEnvFactory(); $jsEnv = $jsEnvFactory->getEnvHtml(); $jsEnv->addOwn('url', 'http://site.com/ajax') ->addOwn('locale', 'ru_RU') ->addOwn('locale_short', 'ru'); $jsEnv->addOwn('one', 1); $jsEnv->addOwn('two', 12.33); $jsEnv->addOwn('three', false); $jsEnv->addOwn('four', null); $jsEnv->addOwn('five', ["one", "two", "three"]); // You can add multiple by key=>value array // $jsEnv->addMultiple($array); $output = $jsEnv->export();
This example give us the next string that you can place on your webpage:
<script> const url = 'http://site.com/ajax'; const locale = 'ru_RU'; const locale_short = 'ru'; const one = 1; const two = 12.33; const three = false; const four = null; const five = '["one","two","three"]'; </script>
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-01