首頁  >  文章  >  後端開發  >  自个儿动手写 PHP acts_as_taggable_on 实现

自个儿动手写 PHP acts_as_taggable_on 实现

WBOY
WBOY原創
2016-06-13 13:20:16716瀏覽

自己动手写 PHP acts_as_taggable_on 实现

写道
这个功能不怎么好总结,看了很多PHP相关的资料 感觉都木有讲清楚,ZF和orm的实现又过于臃肿....

只好 参阅rails的acts_as_taggable_on 说白了 核心就一个sql

select post.*,count(tag.id) as count

from post,tag,taging

where post.id!={当前post.id} #排除自身
and post.id=taging.post_id #限定标签的范围为当前post所拥有的标签集合
and taging.tag_type=post.base_class #限定标签类型为当前post的基本类型
and taging.tag_id=tag.id #限定必须是有效的标签
and tag.name in ({当前post拥有的标签})

group by post.id
order by count desc

鄙视 某些人 教程说完一半后面就没了...

简单的东西都复杂话了 ?
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn