ViewsCounter Bundle
ViewsCounter increments views counts for document/entity., (*1)
Setup the bundle
Step 1: Install ViewsCounterBundle
ViewsCounter bundle is installed using [Composer][1]., (*2)
composer require cengizhancaliskan/views-counter-bundle
Enable ViewsCounterBundle in your AppKernel:, (*3)
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Cengizhan\ViewsCounterBundle\CengizhanViewsCounterBundle(),
];
// ...
}
``` php
<?php, (*4)
namespace YourBundle\YourEntity;, (*5)
use Cengizhan\ViewsCounterBundle\Model\VisitableInterface;
use Cengizhan\ViewsCounterBundle\Traits\VisitableEntityTrait;
use Doctrine\ORM\Mapping as ORM;, (*6)
/**
* @ORM\Entity()
*/
class Article implements VisitableInterface
{
use VisitableEntityTrait;, (*7)
/**
* @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;
}
}, (*8)
## Usage:
``` php
<?php
....
$this->get('views_counter.views_counter')->count($article);
....
How to configure, (*9)
If you can query builder ( recommendation for cached entity ), (*10)
# config.yml
....
cengizhan_views_counter:
use_query_builder: true