mb / secure-display-bundle
此包已被弃用且不再维护。未建议替代包。
MBSecureDisplayBundle 是一个小巧简单的包,通过加密和 JavaScript 保护电子邮件和电话号码。
v1.1
2016-07-05 10:33 UTC
Requires
- php: >=5.3.3
- friendsofsymfony/jsrouting-bundle: ~1.5
- symfony/framework-bundle: >=2.3
- symfony/twig-bundle: >=1.24.1
Requires (Dev)
- phake/phake: ~1
- phpunit/phpunit: ~4
This package is not auto-updated.
Last update: 2022-02-01 12:59:37 UTC
README
MBSecureDisplayBundle 是一个小巧简单的包,通过加密、Ajax 和 JavaScript 保护电子邮件、电话号码以及您希望保护的任何文本免受垃圾邮件机器人侵害。
需求
在安装此包之前,您需要一个正常工作的 FOSJsRoutingBundle 安装。
安装
步骤 1:Composer
首先,您需要将 mb/secure-display-bundle
添加到 composer.json
中
{ "require": { "mb/secure-display-bundle": "dev-master" } }
注意:将 dev-master
替换为此包的最后一个版本。
步骤 2:AppKernel
将包注册到 Symfony AppKernel 中
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( ... new MB\SecureDisplayBundle\MBSecureDisplayBundle() ); return $bundles; } }
步骤 3:配置
在配置文件中定义包的配置
# app/config/config.yml mb_secure_display: # Required, key used to encrypt data key: "my_super_random_secure_key" # Optional, you can customize used template here template: 'MBSecureDisplayBundle::secure_display.html.twig'
步骤 4:路由
注册包的路由以执行 Ajax 请求
# app/config/routing.yml mb_secure_display: resource: "@MBSecureDisplayBundle/Resources/config/routing.yml" prefix: /
步骤 5:资源
发布资源以使用 JavaScript 文件
$ php app/console assets:install --symlink web
在您的布局中添加此行
<script src="{{ asset('bundles/mbsecuredisplay/js/display.js') }}"></script>
声明
{{ some.data|secureDisplay(label, action, attributes) }}
参数
- 标签:可选
- 类型:字符串
- 值:如果 JavaScript 未启用则显示的文本
- 操作:可选
- 类型:字符串
- 值:附加到链接之前的操作(如 "tel:012 345 67" 或 "mailto:john@doe.com")
- 属性:可选
- 类型:数组
- 值:要添加到文本的 HTML 属性
用法
<h4>Here are my personal informations</h4> {# Default usage #} <p>My name is : {{ contact.name|secureDisplay }}</p> {# Custom label when JavaScript is not enabled #} <p>You can find me at : {{ contact.address|secureDisplay('this address is protected') }}</p> {# Transform phone number into clicable link #} {# Can be 'tel', 'mailto', whatever you want #} <p>My phone number is : {{ contact.phoneNumber|secureDisplay(null, 'tel') }}</p> {# Custom html attributes #} <p>My favorite color is : {{ contact.color|secureDisplay(null, null, { 'style': 'color: red' }) }}</p>
当然,您可以按照需要混合这三个参数中的任何一个。