定制 waltertamboer/wtrating 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

waltertamboer/wtrating

Composer 安装命令:

composer require waltertamboer/wtrating

包简介

A Zend Framework 2 module that provides functionality to rate or like something.

README 文档

README

Version 0.0.1

Build Status

Introduction

This is a Zend Framework 2 module that provides functionality to rate or like something.

Requirements

Installation

Add this repository as a submodule to your repository or install using Composer:

{
    "require": {
        "waltertamboer/wtrating": "*"
    }
}

Usage

Setup

Setup the mapper that you want to use. By default this module only comes with a Zend\Db mapper.

'service_manager' => array(
    'factories' => array(
        'wtrating.mapper' => function ($sm) {
            $dbAdapter = $sm->get('... db adapter ...');
            return new \WtRating\Mapper\ZendDbMapper($dbAdapter);
        }
    ),
)

Rate something

To add a rating you could do the following:

public function indexAction()
{
    // The id of the user that is currently logged in or null if there is no user:
    $userId = ...;

    // The type that identifies the rating:
    $typeId = 'my-article-163';

    // The rating to set, make something up:
    $rating = rand();

    $serviceLocator = $this->getServiceLocator();

    // Create a new rating:
    $rating = $serviceLocator->create('wtrating.rating');
    $rating->setTypeId($typeId);
    $rating->setUserId($userId);
    $rating->setRating($rating);

    // Save the rating to the storage device:
    $ratingService = $serviceLocator->get('wtrating.service');
    $ratingService->persist($rating);

    // Retrieve the rating set that contains information like avarage rating,
    // amount of rates, etc.
    return new ViewModel(array(
        'ratingSet' => $ratingService->getRatingSet($typeId)
    ));
}

Show ratings

There is a view helper that can be invoked:

$this->wtRating($ratingSet);

It's possible to add attributes as well:

$this->wtRating($this->ratingSet, array(
    'class' => 'rating'
));

If you want to change the HTML element you can use the third parameter:

$this->wtRating($this->ratingSet, array(), 'div');

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2012-11-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固