Home  >  Article  >  Backend Development  >  自个儿动手写 PHP acts_as_taggable_on 实现

自个儿动手写 PHP acts_as_taggable_on 实现

WBOY
WBOYOriginal
2016-06-13 13:20:16716browse

自己动手写 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

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

简单的东西都复杂话了 ?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn