迅睿開(kāi)源框架是一款PHP8高性能·簡(jiǎn)單易用的PHP開(kāi)源開(kāi)發(fā)框架, 基于MIT開(kāi)源許可協(xié)議發(fā)布,不限制商業(yè)使用,以多端互聯(lián)為設(shè)計(jì)理念, 支持的微信公眾號(hào)、小程序、APP客戶端、移動(dòng)端網(wǎng)站、PC網(wǎng)站等多終端式管理系統(tǒng)。
業(yè)務(wù)經(jīng)理
微信掃描以上二維碼
028-61286886
技術(shù)咨詢
模板標(biāo)簽里面
查詢判斷當(dāng)前登錄用戶是否收藏了這篇文章?用 table 查詢嗎?
這個(gè)操作走了緩存嗎?每篇文章都查一次哦?好痛苦!感覺(jué)很消耗資源
{table table=1_news_favorite uid=$member.id cid=$id}
{$t.id}
{/table}
用自定義函數(shù),然后做緩存
回復(fù)@易學(xué)習(xí)
我用了自定義函數(shù),但是出來(lái)就系統(tǒng)報(bào)錯(cuò)
{function name=my_favorites param=$member.id cache=0 return=f}{$f}{/function}
function my_favorites($id) { // 這里是寫(xiě)查詢 $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 cid=$id cahe=緩存時(shí)間}
樓上我想過(guò)了,不過(guò)可能當(dāng)時(shí)沒(méi)轉(zhuǎn)彎過(guò)來(lái),善用數(shù)組的話,就簡(jiǎn)單了
{table table=1_news_favorite uid=$member.id cache=3600} {php $my_favorites[] = $t.cid;} {/table} <?php if(in_array($cid, $my_favorites)){ echo '在數(shù)組中存在'; } else { echo '在數(shù)組中不存在'; } ?>
{function name=my_favorites param=$member.id,$id cache=1110 return=f} {if $f} ok {else} no {/if} {/function}
function my_favorites($param) { // 這里是寫(xiě)查詢 list($uid, $cid) = explode($param); return \Phpcmf\Service::M()->table('dr_1_news_favorite')->where('uid', (int)$uid)->where('cid', (int)$cid)->counts();;}
我試過(guò)了,已收藏還是會(huì)顯示 NO ,不然我也不會(huì)提問(wèn)了,就覺(jué)得好奇怪!
出來(lái)的值永遠(yuǎn)是 0
{function name=my_favorites param=1,2 cache=1110 return=f} {if $f} ok {else} no {/if} {/function}
回復(fù)@Booid.com
用死數(shù)據(jù)測(cè)試,1表示用戶id,2表示文章id
我用死數(shù)據(jù)和變量都可以顯示ok
實(shí)測(cè)有效的
那我只能哭了,本地環(huán)境,2個(gè)網(wǎng)站測(cè),都是不能正常顯示的!等我上線了再回來(lái)結(jié)貼吧
用自定義函數(shù),然后做緩存
回復(fù)@易學(xué)習(xí)
我用了自定義函數(shù),但是出來(lái)就系統(tǒng)報(bào)錯(cuò)
{function name=my_favorites param=$member.id cache=0 return=f}{$f}{/function}function my_favorites($id) { // 這里是寫(xiě)查詢 $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 cid=$id cahe=緩存時(shí)間}
{$t.id}
{/table}
樓上我想過(guò)了,不過(guò)可能當(dāng)時(shí)沒(méi)轉(zhuǎn)彎過(guò)來(lái),善用數(shù)組的話,就簡(jiǎn)單了
{table table=1_news_favorite uid=$member.id cache=3600} {php $my_favorites[] = $t.cid;} {/table} <?php if(in_array($cid, $my_favorites)){ echo '在數(shù)組中存在'; } else { echo '在數(shù)組中不存在'; } ?>{function name=my_favorites param=$member.id,$id cache=1110 return=f} {if $f} ok {else} no {/if} {/function}回復(fù)@易學(xué)習(xí)
我試過(guò)了,已收藏還是會(huì)顯示 NO ,不然我也不會(huì)提問(wèn)了,就覺(jué)得好奇怪!
回復(fù)@易學(xué)習(xí)
出來(lái)的值永遠(yuǎn)是 0
{function name=my_favorites param=1,2 cache=1110 return=f} {if $f} ok {else} no {/if} {/function}回復(fù)@Booid.com
用死數(shù)據(jù)測(cè)試,1表示用戶id,2表示文章id
我用死數(shù)據(jù)和變量都可以顯示ok
實(shí)測(cè)有效的
回復(fù)@易學(xué)習(xí)
那我只能哭了,本地環(huán)境,2個(gè)網(wǎng)站測(cè),都是不能正常顯示的!等我上線了再回來(lái)結(jié)貼吧