dev-master
9999999-dev http://github.com/avro/AvroRatingBundleSymfony2 Star Rating Bundle
MIT
The Requires
- php >=5.3.2
- friendsofsymfony/user-bundle *
by Joris de Wit
Wallogit.com
2017 © Pedro Peláez
Symfony2 Star Rating Bundle
Add a star rating to any object., (*1)
Add AvroRatingBundle in your composer.json:, (*2)
{
"require": {
"avro/rating-bundle": "*"
}
}
Now tell composer to download the bundle by running the command:, (*3)
``` bash $ php composer.phar update avro/rating-bundle, (*4)
### Enable the bundle in the kernel: ``` php // app/AppKernel.php new Avro\RatingBundle\AvroRatingBundle
Add CSS ``` html {% stylesheets output='css/compiled/app.css' filter='cssrewrite, less, ?yui_css' ... 'bundles/avrorating/css/avro-rating.css' ... %} {% endstylesheets %}, (*5)
Add JS
``` html
{% javascripts output='js/compiled/app.js' filter='?yui_js'
...
'bundles/avrorating/js/avro-rating.js'
...
%}
{% endjavascripts %}
Dump your assets and watch ``` bash $ php app/console assets:install --symlink=true, (*6)
$ php app/console assetic:dump --watch --force, (*7)
Configuration ------------- No configuration is necessary but does come with some options that allow you to customize it ``` yaml avro_rating: template: 'AvroRatingBundle:Rating:rating.html.twig star_count: 5 min_role: ROLE_USER
Add the rating reference to the object you want to rate, (*8)
``` php <?php // src/Acme/ProductBundle/Document/Product.php, (*9)
namespace Acme\ProductBundle\Document;, (*10)
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;, (*11)
/** * @ODM\Document */ class Product { ..., (*12)
/**
* @ODM\ReferenceOne(targetDocument="Avro\RatingBundle\Document\Rating", cascade={"all"})
*/
protected $rating;
/**
* Set rating
*
* @param Avro\RatingBundle\Document\Rating $rating
* @return Product
*/
public function setRating(\Avro\RatingBundle\Document\Rating $rating)
{
$this->rating = $rating;
return $this;
}
/**
* Get rating
*
* @return Avro\RatingBundle\Document\Rating $rating
*/
public function getRating()
{
return $this->rating;
}
...
}, (*13)
Render the rating in your view ``` html {{ avro_rating(product.rating) }}
And that's it!, (*14)
Symfony2 Star Rating Bundle
MIT