cengizhancaliskan / views-counter-bundle
Symfony document/entity views counter
Installs: 2 114
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4
- symfony/symfony: ^2.7 || ^3.0
Requires (Dev)
- phpunit/phpunit: ~4.8|~5.0
This package is not auto-updated.
Last update: 2023-12-15 16:28:06 UTC
README
ViewsCounter increments views counts for document/entity.
Setup the bundle
Step 1: Install ViewsCounterBundle
ViewsCounter bundle is installed using Composer.
composer require cengizhancaliskan/views-counter-bundle
Enable ViewsCounterBundle in your AppKernel:
// app/AppKernel.php public function registerBundles() { $bundles = [ // ... new Cengizhan\ViewsCounterBundle\CengizhanViewsCounterBundle(), ]; // ... }
Step 2: Configure your entity
<?php namespace YourBundle\YourEntity; use Cengizhan\ViewsCounterBundle\Model\VisitableInterface; use Cengizhan\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 .... cengizhan_views_counter: use_query_builder: true