定制 pianosolo/counter-bundle 二次开发

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

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

pianosolo/counter-bundle

Composer 安装命令:

composer require pianosolo/counter-bundle

包简介

Counter Bundle of Symfony

README 文档

README

Symfony bundle helps to easily add a counter to entities. Using CounterTrait in entities will create a Counter entity relation automatically. Then you can easily add clicks to the counter. You can also add fake counts to your entites by keeping the real count.

Latest Stable Version Latest Unstable Version License

Installation

1-) Tell composer to download by running the command:

composer require pianosolo/counter-bundle

2-) Add the bundle to AppKernel

<?php
// app/AppKernel.php
	
public function registerBundles()
{
    $bundles = array(
        // ...
        new PianoSolo\CounterBundle\PianoSoloCounterBundle(),
    );
}

Usage

1-) Add CounterTrait to your entity.

<?php

namespace MyBundle\Entity;

use PianoSolo\Traits\CounterTrait;

class MyEntity
{
    use CounterTrait;
    
    //...
}

2-) EventListener will create a new Counter for your entity while persisting your entity.

    $myEntity = new MyEntity();
    $entityManager->persist($myEntity);
    $entityManager->flush();

3-) Call Counter and add clicks.

<?php

namespace MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function showEntityAction()
    {
        //...
        
        $myEntity = $myEntityRepository->findOneBy(array('id' => $id));
        $myEntity->getCounter()->addClick(5); // Default value of parameter is 1
        
        $entityManager->persist($myEntity);
        $entityManager->flush();
    }
}

4-) Get Count

    $count = $myEntity->getCounter()->getCount();
    {{ myEntity.counter.count }}

Adding Fake Count

You can add fake counts to your entities and keep the real counts. Whenever you want you can delete this fake counts.

    // Example initial count values of entity
    $count = $myEntity->getCounter()->getCount(); // return 10
    $realCount = $myEntity->getCounter()->getRealCount(); // return 10

    // Adding fake count
    $myEntity->getCounter()->setCorrectionCount(100);
    $entityManager->persist($myEntity);
    $entityManager->flush();

    // Keeping real count
    $count = $myEntity->getCounter()->getCount(); // return 110
    $realCount = $myEntity->getCounter()->getRealCount(); // return 10

    // Delete fake count
    $myEntity->getCounter()->setCorrectionCount(0):
    $entityManager->persist($myEntity);
    $entityManager->flush();

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固