albertborsos / yii2-gdpr-cookie-consent
GDPR 兼容的 Cookie Consent 小部件允许用户选择他们想要接受的 cookie 类型。
1.3.0
2021-11-02 13:10 UTC
Requires
- php: >=5.6.0
- 2amigos/yii2-switch-widget: ^1.0
- albertborsos/yii2-ddd: ~0.2
- bower-asset/cookieconsent: ~3.1
- yiisoft/yii2: ~2.0.0
Requires (Dev)
- codeception/codeception: ^2.4
- codeception/mockery-module: ^0.2.2
- codeception/specify: ~0.4.6
- codeception/verify: ~0.4.0
- mito/yii2-coding-standards: ~2.0.0@beta
- satooshi/php-coveralls: ~1.0
- dev-master
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0.0-beta2
- 1.0.0-beta1
- 0.1.0-beta10
- 0.1.0-beta9
- 0.1.0-beta8
- 0.1.0-beta7
- 0.1.0-beta6
- 0.1.0-beta5
- 0.1.0-beta4
- 0.1.0-beta3
- 0.1.0-beta2
- 0.1.0-beta1
- dev-dependabot/composer/guzzlehttp/psr7-1.9.1
- dev-dependabot/composer/guzzlehttp/guzzle-6.5.8
This package is auto-updated.
Last update: 2024-09-19 21:50:02 UTC
README
GDPR 兼容的 Cookie Consent 小部件允许用户选择他们想要接受的 cookie 类型。
安装
安装此扩展的首选方法是通过 composer。
运行
composer require --prefer-dist albertborsos/yii2-gdpr-cookie-consent
使用方法
将组件添加到您的配置文件中
<?php return [ // ... 'components' => [ // ... 'cookieConsent' => [ 'class' => \albertborsos\cookieconsent\Component::class, 'urlSettings' => ['/site/cookie-settings'], 'urlPrivacyPolicy' => ['/site/privacy-policy'], 'documents' => [ ['name' => 'Privacy Policy', 'url' => ['/docs/privacy-policy.pdf']], ], 'disabledCategories' => [ \albertborsos\cookieconsent\helpers\CookieHelper::CATEGORY_BEHAVIOR, ], ], // ... 'i18n' => [ // ... 'translations' => [ 'cookieconsent/*' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@vendor/albertborsos/yii2-gdpr-cookie-consent/src/messages', ], ], // ... ], ], // ... ];
在布局中注册小部件。例如,在一个 _cookieconsent.php
部分视图中。
<?php /** @var \albertborsos\cookieconsent\Component $component */ $component = Yii::$app->cookieConsent; $component->registerWidget([ 'policyLink' => ['/default/cookie-settings'], 'policyLinkText' => \yii\helpers\Html::tag('i', null, ['class' => 'fa fa-cog']) . ' Beállítások', 'pluginOptions' => [ 'expiryDays' => 365, 'hasTransition' => false, 'revokeBtn' => '<div class="cc-revoke {{classes}}">Cookie Policy</div>', ], ]);
将 cookie 设置表单添加到您的任何控制器中
<?php namespace app\controllers; class SiteController extends \yii\web\Controller { public function actions() { return [ 'cookie-settings' => \albertborsos\cookieconsent\actions\CookieSettingsAction::class, 'privacy-policy' => \albertborsos\cookieconsent\actions\PrivacyPolicyAction::class, ]; } }
使用以下方式检查用户是否允许使用相关小部件:CookieConsent 辅助类
<?php use \albertborsos\cookieconsent\helpers\CookieHelper; use \albertborsos\cookieconsent\Component; if(CookieHelper::isAllowedType(CookieHelper::TYPE_GOOGLE_ANALYTICS)){ // register GA script } if(CookieHelper::isAllowedCategory(CookieHelper::CATEGORY_BEHAVIOR)){ // register hotjar script }