查询判断当前登录用户是否收藏了这篇文章 迅睿框架 更新 2020-11-25 15:39:48 Booid.com 模板标签里面查询判断当前登录用户是否收藏了这篇文章?用 table 查询吗?这个操作走了缓存吗?每篇文章都查一次哦?好痛苦!感觉很消耗资源{table table=1_news_favorite uid=$member.id cid=$id}{$t.id}{/table}
{table table=1_news_favorite uid=$member.id cid=$id cahe=缓存时间}
{$t.id}
{/table}
{function name=my_favorites param=$member.id cache=0 return=f}{$f}{/function}function my_favorites($id) { // 这里是写查询 $rt = \Phpcmf\Service::M()->db->table('dr_1_news_favorite')->where('uid', $id)->get(); if ($rt) { $rows = $rt->getResultArray(); return $rows; } }{table table=1_news_favorite uid=$member.id cache=3600} {php $my_favorites[] = $t.cid;} {/table} <?php if(in_array($cid, $my_favorites)){ echo '在数组中存在'; } else { echo '在数组中不存在'; } ?>{function name=my_favorites param=$member.id,$id cache=1110 return=f} {if $f} ok {else} no {/if} {/function}{function name=my_favorites param=1,2 cache=1110 return=f} {if $f} ok {else} no {/if} {/function}Booid.com用死数据测试,1表示用户id,2表示文章id我用死数据和变量都可以显示ok