bizley / cookiemonster
用于管理Cookie警告的Yii扩展。
1.1.0
2021-03-07 18:46 UTC
Requires
- php: >=5.4
- yiisoft/yii2: *
Requires (Dev)
- php: >=7.2
- infection/infection: *
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-09-20 10:20:39 UTC
README
用于管理Cookie警告的Yii 2扩展
这是用来做什么的?
2009年,欧盟在“电子隐私”指令的框架内寻求新的法规,将Cookie视为对隐私的潜在威胁,因为用户通常不知道他们正在被追踪。
此扩展为Yii网站添加了有关Cookie的信息。
需求
Yii 2
安装
通过将包添加到您的composer.json中通过composer获取它
{ "require": { "bizley/cookiemonster": "*" } }
或运行 composer require bizley/cookiemonster
。
使用方法
在主模板文件中添加此代码,在 <?php $this->endBody() ?>
之前
<?= \bizley\cookiemonster\CookieMonster::widget() ?>
这将渲染具有所有默认选项(以及“顶部”布局)的小部件。
如果您想进行配置,请添加选项数组。
<?= \bizley\cookiemonster\CookieMonster::widget([/* options here */]) ?>
所有选项(以及选项的选项)如下所述。
例如,如果您想在按钮上使用自定义消息并使用“底部”布局,请设置
<?= \bizley\cookiemonster\CookieMonster::widget([
'content' => [
'buttonMessage' => 'OK', // instead of default 'I understand'
],
'mode' => 'bottom'
]); ?>
配置
您可以通过传递数组到具有以下键的widget()方法来设置小部件选项
box
- 数组 div的CSS类、样式和HTML选项content
- 数组 警告和按钮消息cookie
- 数组 Cookie选项mode
- 字符串 小部件布局选择params
- 混合 传递到自定义小部件布局的用户参数
box
选项
addButtonStyle
- 数组 要添加或用新值替换的按钮CSS样式选项列表,例如 'padding-right' => '20px', 'font-weight' => 'bold'addInnerStyle
- 数组 要添加或用新值替换的内部div CSS样式选项列表addOuterStyle
- 数组 要添加或用新值替换的外部div CSS样式选项列表buttonHtmlOptions
- 数组 要添加的按钮HTML选项列表(除样式和类外)classButton
- 字符串 按钮类或类(用空格分隔),默认 'CookieMonsterOk'classInner
- 字符串 内部div类或类(用空格分隔)classOuter
- 字符串 外部div类或类(用空格分隔),默认 'CookieMonsterBox'innerHtmlOptions
- 数组 要添加的内部div HTML选项列表(除样式和类外)outerHtmlOptions
- 数组 要添加的外部div HTML选项列表(除样式和类外)replaceButtonStyle
- 数组 要替换为新值或删除的按钮CSS样式选项列表,例如 'margin-left' => '10px', 'font-size' => falsereplaceInnerStyle
- 数组 要替换为新值或删除的内部div CSS样式选项列表replaceOuterStyle
- 数组 要替换为新值或删除的外部div CSS样式选项列表setButtonStyle
- 数组 要设置的按钮CSS样式选项列表,以替换默认值setInnerStyle
- 数组 要设置的内部div CSS样式选项列表,以替换默认值setOuterStyle
- 数组 要设置的外部div CSS样式选项列表,以替换默认值view
- 字符串 自定义视图的路径(如果 $mode 设置为 'custom',则为必需),对于在部件文件夹外的视图,使用别名路径,例如 '@app/views/cookie'
content
选项
buttonMessage
- 字符串 按钮原始消息,如 Yii::t() 中的 $message,默认 '我明白'buttonParams
- 数组 适用于按钮消息的参数,如 Yii::t() 中的 $params,默认 array()category
- 字符串 消息类别,如 Yii::t() 中的 $category,默认 'app'language
- 字符串 目标语言,如 Yii::t() 中的 $language,默认 nullmainMessage
- 字符串 主要原始消息,如 Yii::t() 中的 $message,默认 '我们在网站上使用饼干来帮助我们提供最佳的在线体验。通过继续使用我们的网站,你同意我们使用饼干。或者,你可以在浏览器的设置中管理它们。'mainParams
- 数组 适用于主要消息的参数,如 Yii::t() 中的 $params,默认 array()
cookie
选项
domain
- 字符串 饼干的域名,默认当前文档位置的 host 部分expires
- 整数 此饼干有效的天数,默认 30max-age
- 整数 最大饼干年龄(以秒为单位)path
- 字符串 饼干的路径,默认 '/'secure
- 布尔值 是否应通过安全协议(如 https)传输饼干,默认 falsesameSite
- 字符串 'lax'(默认),'strict' 或 'none'
mode
可能的值
bottom
- 底部条带box
- 右下角框custom
- 用户定义的自定义模式(需要设置box[view]
)top
- 顶部条带,默认
默认布局
底部
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;bottom:0;left:0;width:100%;box-shadow:0 -2px 2px #000" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
框
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;bottom:20px;right:20px;width:300px;box-shadow:-2px 2px 2px #000;border-radius:10px" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
顶部
<div style="display:none;z-index:10000;position:fixed;background-color:#fff;font-size:12px;color:#000;top:0;left:0;width:100%;box-shadow:0 2px 2px #000" class="CookieMonsterBox"> <div style="margin:10px" class=""> We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.<button style="margin-left:10px" class="CookieMonsterOk" type="button">I understand</button> </div> </div>
Yii 1.1 版本
您可以在 https://github.com/bizley/Yii-CookieMonster 找到 Yii 1.1 版本