用户点赞 v1.1.0
数据统计方法,新增特性
2023-05-12 更新日志
  • 数据统计方法,新增特性
用户点赞

模块介绍

「用户点赞」是一个提供快速构建用户点赞系统的功能

功能特性

  • 多场景适用
  • 一键增加喜欢按钮

三步实现一个喜欢系统

第一步,实现一个需要喜欢的业务场景,比如 文章(Post) 喜欢

class PostMemberLikeBiz extends AbstractMemberLikeBiz
{
    const NAME = 'post';

    public function name()
    {
        return self::NAME;
    }

    public function title()
    {
        return 'Post喜欢';
    }

    public function memberMenu()
    {
        return [
            'title' => '内容',
            'icon' => 'list',
            'sort' => 100,
            'children' => [
                [
                    'title' => '喜欢的Post',
                    'url' => modstart_web_url('member_like/' . self::name()),
                ],
            ]
        ];
    }

    public function memberTitle()
    {
        return '喜欢的Post';
    }

    public function memberGridItem($item)
    {
        $post = ModelUtil::get('post', $item['bizId']);
        return TextLink::primary(htmlspecialchars($post['title']), modstart_web_url('post/' . $post['id']), 'target="_blank"');
    }
}

第二步,注册到喜欢系统中

\Module\MemberLike\Biz\MemberLikeBiz::register(PostMemberLikeBiz::class);

第三步,引入一个喜欢按钮

@include('module::MemberLike.View.inc.LikeBtn',['biz'=>'post','bizId'=>'文章ID'])
QQ
微信