hyoa / twig-profiler-variables-bundle
显示使用 render 方法发送到 twig 的变量
1.0.3
2019-01-28 09:45 UTC
Requires
- opis/closure: ^3.1
- symfony/framework-bundle: ~3.4|~4.0
- symfony/templating: ~3.4|~4.0
- symfony/twig-bundle: ~3.4|~4.0
- symfony/var-dumper: ~3.4|~4.0
- symfony/yaml: ~3.4|~4.0
- twig/twig: ~1.0|~2.6
Requires (Dev)
- phpunit/phpunit: ~7.5
- symfony/phpunit-bridge: ^4.2
This package is auto-updated.
Last update: 2024-09-28 23:16:45 UTC
README
描述
允许查看控制器发送到 twig 模板的变量。无法序列化的变量将被忽略(包含闭包的变量)
安装
该组件旨在与 Symfony 3.4 或 4.x 版本一起使用。不支持旧版本。
使用 Composer 安装组件
composer require --dev hyoa/twig-profiler-variables-bundle dev-master
在您的内核中启用组件
####Symfony 4.x
# config/packages/framework.yaml framework: ... templating: engines: ['profiler_variables']
// config/bundles.php <?php return [ ... Hyoa\TwigProfilerVariablesBundle\TwigProfilerVariablesBundle::class => ['dev' => true] ];
####Symfony 3.4.x
# app/config/config_dev.yml framework: ... templating: engines: ['profiler_variables']
// app/AppKernel.php <?php public function registerBundles() { ... if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { ... if ('dev' === $this->getEnvironment()) { ... $bundles[] = new \Hyoa\TwigProfilerVariablesBundle\TwigProfilerVariablesBundle(); } } return $bundles; }
示例
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; class HomeController extends AbstractController { /** * @Route("/") */ public function indexAction() { return $this->render( 'home.html.twig', [ 'page' => 'home', 'users' => [ ['id' => 1, 'name' => 'toto'], ['id' => 2, 'name' => 'tata'], ] ] ); } }
测试
唯一的测试是一个集成测试,它断言分析器正确接收了控制器发送的变量。您可以按以下方式运行它: vendor/bin/phpunit
