gulaandrij / views-counter-bundle
Symfony document/entity views counter
Installs: 117
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=7.1
- doctrine/doctrine-bundle: ^1.0 || ^2
- doctrine/orm: 2.6.* || 2.7.*
- symfony/config: ^2.7 || ^3.0 || ^4.0
- symfony/dependency-injection: ^2.7 || ^3.0 || ^4.0
- symfony/framework-bundle: ^2.7 || ^3.0 || ^4.0
- symfony/http-foundation: ^2.7 || ^3.0 || ^4.0
- symfony/http-kernel: ^2.7 || ^3.0 || ^4.0
- symfony/routing: ^4.1
- symfony/var-dumper: ^4.1
Requires (Dev)
- gulaandrij/coding-standard: ^1.0.2
- liip/functional-test-bundle: ^3.3
- symfony/phpunit-bridge: ^4.1
- symfony/yaml: ^4.1
This package is auto-updated.
Last update: 2024-10-29 04:53:34 UTC
README
ViewsCounter increments views counts for document/entity.
Setup the bundle
Step 1: Install ViewsCounterBundle
ViewsCounter bundle is installed using Composer.
composer require gulaandrij/views-counter-bundle
Enable ViewsCounterBundle in your AppKernel:
// app/AppKernel.php public function registerBundles() { $bundles = [ // ... new Lavulator\ViewsCounterBundle\CengizhanViewsCounterBundle(), ]; // ... }
Step 2: Configure your entity
<?php namespace YourBundle\YourEntity; use Lavulator\ViewsCounterBundle\Model\VisitableInterface; use Lavulator\ViewsCounterBundle\Traits\VisitableEntityTrait; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class Article implements VisitableInterface { use VisitableEntityTrait; /** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; /** * @ORM\Column(name="title", type="string") */ protected $title; public function getId() { return $this->id; } public function setTitle($title) { $this->title = $title; } public function getTitle() { return $this->title; } }
Usage:
<?php .... $this->get('views_counter.views_counter')->count($article); ....
How to configure
If you can query builder ( recommendation for cached entity )
# config.yml .... lavulator_views_counter: use_query_builder: true