ekyna / cookie-consent-bundle
Cookie 允许(GDPR)
0.7.x-dev
2020-11-25 13:05 UTC
Requires
- php: >=7.2
- doctrine/doctrine-bundle: ~1.4
- symfony/form: ^3.4|^4.0
- symfony/framework-bundle: ^3.4|^4.0
- symfony/twig-bundle: ^3.4|^4.0
- symfony/validator: ^3.4|^4.0
README
安装
composer require ekyna/cookie-consent-bundle
注册包和路由
// app/AppKernel.php public function registerBundles() { $bundles = [ // ... new Ekyna\Bundle\CookieConsentBundle\EkynaCookieConsentBundle(), ]; // ... }
# app/config/routing.yml ekyna_cookie_consent: resource: "@EkynaCookieConsentBundle/Resources/config/routing.yaml"
使用 Twig 函数
{# base.html.twig #} <!DOCTYPE html> <html lang="en"> <head> <link href="{{ asset('bundles/ekynacookieconsent/css/cookie-consent.css') }}" rel="stylesheet" type="text/css" /> <head> <body> {# ... #} {% block javascripts %} {# Renders the cookie consent widget (if not yet consented) #} {{ ekyna_cookie_consent_render() }} {# Check if cookie category has user consent ('analytic', 'marketing' or 'social_network') #} {% if ekyna_cookie_consent_category_allowed('analytic') %} <script src="https://example.org/analytic.js"></script> {% endif %} {% endblock javascripts %} </body> </html>
ekyna_cookie_consent_render() 选项及其默认值
{{ ekyna_cookie_consent_render({ render_if_saved: false, // Whether to render even if consent has been saved. expanded: false, // Whether to show settings dialog: true // Whether to render as a dialog/popup }) }}
配置
默认值下的可用配置。
# app/config/config.yml ekyna_cookie_consent: name: Cookie_Content # The consent cookie name read_more_route: ~ # Route name to your privacy policy page position: centered # Widget positioning ('centered' or 'bottom-right') categories: # Cookies categories the user has to consent - analytic - marketing - social_network persist: true # Whether to persist user consent
待办事项
- 加密 cookie 允许实体中的 IP 属性。