hyoa/twig-profiler-variables-bundle

显示使用 render 方法发送到 twig 的变量

安装: 9

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.3 2019-01-28 09:45 UTC

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'],
                ]
            ]
        );
    }
}

Profiler page example

测试

唯一的测试是一个集成测试,它断言分析器正确接收了控制器发送的变量。您可以按以下方式运行它: vendor/bin/phpunit