irishdan/js-settings-bundle
Composer 安装命令:
composer require irishdan/js-settings-bundle
包简介
A bundle for injecting data as javascript into a page
关键字:
README 文档
README
This bundle provides a service and a twig extension for easily injecting data into a webpage as a javascript object.
1: Installation
Install with composer.
composer require irishdan/js-settings-bundle
Step 2: Enable the Bundle
Enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new IrishDan\JsSettingsBundle\JsSettingsBundle(), ); // ... } // ... }
Import the service definition in your config.yml file imports:
- { resource: "@JsSettingsBundle/Resources/config/services.yml" }
3: Configuration
No configuration is needed. Some is available.
In config.yml you can add:
js_settings:
object_name: 'JsData'
defaults:
local: "%locale%"
page_data:
site: 'www.example.com'
object_name: By default the Javascript object it Called 'Symfony'. You can change the use 'JsData', by using the configuration above.
defaults: Default values are added to the javascript object by default and are always available.
4: Usage
The bundle provides a single service 'js_settings.settings' to add data and remove data from the javascript object.
To add variables simple pass in a key value pair like so:
// The key can be a string... $this->get('js_settings.settings')->addData('key', $values); // The key can be an array... $this->get('js_settings.settings')->addData(['first_key', 'second_key'], $values); // The key can be index notation $this->get('js_settings.settings')->addData('[first_key][second_key]', $values);
Or, use pushData to push the data into an array.
$this->get('js_settings.settings')->pushData('[first_key][second_key]', $values);
To inject the javascript object into the page, simply add the following twig function to your twig template
{{ get_js_settings() }}
irishdan/js-settings-bundle 适用场景与选型建议
irishdan/js-settings-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「twig」 「javascript」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 irishdan/js-settings-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 irishdan/js-settings-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 irishdan/js-settings-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
The bundle for easy using json-rpc api on your project
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-02