lsv/hashidsbundle
Symfony 扩展包,用于将 hashids 库集成到容器中
1.0.2
2016-05-12 01:13 UTC
Requires
- hashids/hashids: ^1.0
- symfony/config: ^2.7|^3.0
- symfony/dependency-injection: ^2.7|^3.0
- symfony/http-kernel: ^2.7|^3.0
- symfony/twig-bridge: ^2.7|^3.0
This package is auto-updated.
Last update: 2024-08-27 21:48:58 UTC
README
适用于 Symfony ^2.7 以及 ^3.0
安装
composer
composer require lsv/hashidsbundle
或者将其添加到您的 composer.json 文件中
"require": { "lsv/hashidsbundle": "^1.0" }
启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new \Lsv\HashidsBundle\LsvHashidsBundle(), ); }
配置
所有配置都是可选的,但以下是可用的配置
lsv_hashids: # Salt is default the same as your app secret salt: "%secret%" # Length is default 8 length: 8 # Alphabet is default "abcdefghij1234567890" - Default in hashids alphabet: "abcdefghij1234567890"
使用方法
控制器
在您的控制器中,您可以使用
$this->get('lsv_hashids')->encode($id); $this->get('lsv_hashids')->decode($string);
Twig
还增加了 3 个 Twig 方法
id | hashids id | encode_hashids string | decode_hashids