kikwik / cookie-bundle
Symfony 5 的 Cookie 横幅
v1.0.7
2023-10-07 11:40 UTC
Requires
- php: >=7.2.5
- ext-json: *
- doctrine/doctrine-bundle: ^2.0
- doctrine/orm: ^2.7|^3.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/translation: ^5.4|^6.0
- symfony/twig-bundle: ^5.4|^6.0
Requires (Dev)
- nyholm/symfony-bundle-test: ^2.0
- symfony/browser-kit: ^5.4|^6.0
- symfony/phpunit-bridge: ^5.4|^6.0
README
Symfony 5+ 的 Cookie 横幅
安装
打开命令行,进入项目目录,并执行以下命令以下载此包的最新稳定版本
$ composer require kikwik/cookie-bundle
更新数据库以创建 kw_cookie_consent_log 表
$ php bin/console make:migration $ php bin/console doctrine:migrations:migrate
配置
创建 config/packages/kikwik_cookie.yaml
配置文件并清除缓存
kikwik_cookie: cookie_prefix: 'kwc_consent' # the prefix for the cookie name (default is kwc_consent) cookie_lifetime: 180 # number days after cookie expiration (default is 6 months) consent_version: '1.0' # consent version (change to invalidate old consents) privacy_policy: 'app_privacy' # route or url for privacy policy (default is null) cookie_policy: 'app_cookie' # route or url for cookie policy (default is null) categories: [ ] # list of available categories, example: [ 'functional', 'analytics', 'profiling', 'marketing' ] enable_consent_log: false # save user consent in database (default is false) banner_classes: wrapper: 'position-fixed bottom-0 start-0 end-0 p-1 border-top border-3 bg-white' actionWrapper: 'float-md-end text-center' btnAccept: 'btn btn-sm btn-success my-1' btnDeny: 'btn btn-sm btn-danger my-1' btnChoose: 'btn btn-sm btn-warning my-1' btnPrivacy: 'm-1' btnCookie: 'm-1'
在 config/routes/kikwik_cookie.yaml
中导入路由包
kikwik_cookie_bundle: resource: '@KikwikCookieBundle/Resources/config/routes.xml' prefix: '/'
将翻译文件从 vendor/kikwik/cookie-bundle/src/Resources/translations/KikwikCookieBundle.xx.yaml
复制到 translations
目录以更改横幅文本
在 config/packages/twig.yaml
中创建一个 twig 全局变量以在模板中使用 ConsentManager
twig: globals: cookieConsentManager: '@Kikwik\CookieBundle\Service\ConsentManager'
{% if cookieConsentManager.categoryAllowed('analytics') %} <script> ... </script> {% endif %}