PHP Classes

File: Resources/doc/clicks_or_views.rst

Recommend this page to a friend!
  Classes of Manolo Salsas   Msalsas PHP Voting System Project Bundle   Resources/doc/clicks_or_views.rst   Download  
File: Resources/doc/clicks_or_views.rst
Role: Example script
Content type: text/plain
Description: Example script
Class: Msalsas PHP Voting System Project Bundle
Symfony bundle to manage votes of users on content
Author: By
Last change: Update of Resources/doc/clicks_or_views.rst
Date: 2 years ago
Size: 919 bytes
 

Contents

Class file image Download
MsalsasVotingBundle clicks or views
===================================

For incrementing the clicks or views of a reference you have to type-hint the ``Clicker`` in a
controller action and call ``addClick`` with the reference id (you will have to configure this route):


.. code-block:: php

    <?php

   
public function postClick($postId, Clicker $clicker): Response
   
{
       
$clicker->addClick($post->getId());

       
// ...
   
}

The ``addClick`` method will check if the user has already clicked. If it is an anonymous
user
, it will check for the client IP.

If
you want to make use of views instead of clicks, just override the clicks translation
and call ``$clicker->addClick($post->getId())`` on the post view controller action.


..
code-block:: php

   
<?php

   
public function postShow($postId, Clicker $clicker): Response
   
{
       
$clicker->addClick($post->getId());

       
// ...
   
}