hospect/php-vars-to-js-bundle
最新稳定版本:1.0.2
Composer 安装命令:
composer require hospect/php-vars-to-js-bundle
包简介
Transformation of PHP vars to JS for Symfony2 with Twig
README 文档
README
Description
Bundle allows you to avoid horrible statements in Twig templates while setting JS variables from PHP ones, like:
var someJsVar = '{{ somePhpVar }}', anotherJsVar = '{{ anotherPhpVar }}';
Installation
Simply require it with composer:
composer require hospect/php-vars-to-js-bundle
And register in your AppKernel.php:
public function registerBundles() { $bundles = array( // some other bundles... new \Hospect\PhpVarsToJsBundle\HospectPhpToJsBundle(), ); return $bundles; }
Usage
In your controller call:
$this->get('php_to_js')->put([ 'someJsVar' => $somePhpVar, // more vars here... ]);
Then in Twig template (probably that will be useful to move it to layout):
<script> {{ initPhpVars() }} </script>
统计信息
- 总下载量: 31.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-16