我使用十月,我已经使用构建器制作了插件,我只是在菜单中添加了通知图标。
我想显示“!”如果有新项目并隐藏“!”如果用户单击该按钮(它会打开引导模式)。当我添加新项目时,它显示“!”再次等等...我不知道最好的方法是什么。如果您能帮我解决这个问题,谢谢您。
菜单:
<li>
<a data-toggle="modal" data-target="#itemModal"><i class="fa fa-bell"></i>
<span>! {{ Item }}</span></a>
</li>
代码:
function onStart()
{
$this['Item'] = Db::table('items')->count();
}
最佳答案
为此,您需要数据库表,并且需要保存上次查看/点击日期。
所以这里的想法就像您将在用户单击!
时添加当前日期,您将显示引导模式
并触发ajax请求并设置当前日期。
当时触发ajax请求并为参数添加新日期。
为此,您可以使用 CMS 默认参数表
<?php
use System\Models\Parameter;
....
// something like this in ajax request
Parameter::set('your_plugin_name::items.last_click_date', time() );
// this is when page reload
use System\Models\Parameter;
function onStart()
{
// now
$lastClickDate = Parameter::get('your_plugin_name::items.last_click_date');
if($lastClickDate == null) {
// first time it will just count items directly as user never click on icon
$count = Db::table('items')->count();
}
else {
// new this will call next time as user called that modal and we added click date
// so we compare if any record added after that date if it is then show `!`
$count = Db::table('items')->where('created_at', '>', $lastClickDate)->count();
}
$this['item_count'] = $count;
$this['new_items'] = $count > 0 ? true : false;
}
html
<li>
<a data-toggle="modal" data-target="#itemModal">
<i class="fa fa-bell"></i>
{% if new_items %}
<span>! {{ item_count }} </span>
{% endif %}
</a>
</li
如果您遇到任何问题,请添加评论。
关于php - 通知图标点击后隐藏号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52141783/