ideato/star-rating-bundle

简单的星级评分系统的Symfony Bundle

安装次数: 659

依赖者: 0

建议者: 0

安全: 0

星标: 3

关注者: 5

分支: 0

语言:JavaScript

类型:symfony-bundle

dev-master 2014-08-01 13:04 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:26:35 UTC


README

StarRatingBundle 是一个用于简单星级评分系统的Symfony Bundle。你可以使用自己的JavaScript库,但它也包含了 jQuery Raty 插件,如果你希望直接安装和使用这个Bundle。

安装

  • 通过Composer安装Bundle

      composer require ideato/star-rating-bundle "dev-master"
    
  • 将IdeatoStarRatingBundle添加到应用程序内核

      // app/AppKernel.php
      public function registerBundles()
      {
      		return array(
      			// ...
      			new Ideato\StarRatingBundle\IdeatoStarRatingBundle(),
      			// ...
      		);
      }
    
  • 使用Doctrine更新数据库模式

      app/console doctrine:schema:update --force
    
  • 包含路由配置

      #app/config/routing.yml
      _ideato_starrating:
          resource: "@IdeatoStarRatingBundle/Resources/config/routing.yml"
    

配置

如果你想要使用包含的 jQuery Raty 插件,你需要做以下操作

  • 在允许的Assetic Bundle中添加Bundle

      #app/config.yml
      assetic:
      	#...
      	bundles:        [ IdeatoStarRatingBundle ]
    
  • 加载静态文件

      {% javascripts
      	'//ajax.googleapis.ac.cn/ajax/libs/jquery/1.10.2/jquery.min.js'
      	'@IdeatoStarRatingBundle/Resources/public/jquery.raty.js'
      	'@IdeatoStarRatingBundle/Resources/public/jquery.starrating.js'
      %}
      <script type="text/javascript" src="{{ asset_url }}"></script>
      {% endjavascripts %}
    
      {% stylesheets
      	"@IdeatoStarRatingBundle/Resources/public/jquery.raty.css" filter="cssrewrite" %}
      <link rel="stylesheet" href="{{ asset_url }}" />
      {% endstylesheets %}
    
  • 安装资产并重新生成静态文件

      app/console assets:install web
      app/console assetic:dump
    

使用方法

如果你选择使用包含的jQuery插件,你只需在页面中渲染星级评分控制器

	{{ render(
		controller( "IdeatoStarRatingBundle:StarRating:displayRate", {
			contentId: post.id
		})
	) }}

你需要根据元素的id自定义 contentId 参数。控制器会自动渲染带有当前分数的星级评分。类似于以下截图

这样一切就已经启用,用户可以开始对你的资源进行评分。

附加功能

你可以完全重写位于 jquery.starrating.js 的评分逻辑。最简单的方法是将文件复制并粘贴到你的Bundle中,并使用你自己的JavaScript文件。

待办事项

  • 添加新的表格以注册单个评分
  • 防止多次投票