当前位置:Gxlcms > PHP教程 > 自个儿动手写PHPacts_as_taggable_on实现

自个儿动手写PHPacts_as_taggable_on实现

时间:2021-07-01 10:21:17 帮助过:3人阅读

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

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

简单的东西都复杂话了

?

人气教程排行