polifonic/twig-validator-extension
Composer 安装命令:
composer require polifonic/twig-validator-extension
包简介
A Twig extension to validate objects inside a Twig template
关键字:
README 文档
README
A simple Twig extension that adds a valid filter to be used in twig templates.
With this filter you can test if objects are valid inside a twig template and generate the appropriate markup based on the result.
Installation
Add the package to your app's composer.json:
"require": { "polifonic/twig-validator-extension": "^1.0", }
As a Twig Extension
Create an instance of TwigValidatorExtension and add it to the Twig environment just like any other twig extension.
The TwigValidatorExtension constructor needs to be passed a validator (an instance of Symfony\Component\Validator\Validator\ValidatorInterface).
use Polifonic\Twig\Extension\Validator\TwigValidatorExtension; $validator = ...; $twig = new Twig_Environment($loader); $twig->addExtension(new TwigValidatorExtension($validator));
As a Symfony bundle
The package includes a Symfony bundle named TwigValidatorBundle. This bundle
will automatically add the TwigValidatorExtension to twig.
Enable the TwigValidatorBundle symfony bundle by adding it to your app's kernel:
# app/AppKernel.php public function regsiterBundles() { $bundles = array( ... new Polifonic\Twig\Extension\Validator\Symfony\TwigValidatorBundle(), ); }
Usage
{% if object|valid %}...{% endif %}
With validation groups:
{% if object|valid([ "group1", "group2" ]) %}...{% endif %}
统计信息
- 总下载量: 8.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-26