dongzhuo2371 2011-12-15 04:58
浏览 14
已采纳

CakePHP评级插件中的不同型号

I have a site that listings mp3 files in various categories. The site is in CakePHP and I am using the CakePHP star rating plugin for the rating functionality. The songs are categorized based on Albums, Singer and Music director so I need to implement rating for each of these. The rating plugin now I am using has an option for specify the model. It's model class is something like this :

class Rating extends Model {
  var $name = 'Rating';

  var $validate = array(
    'user_id'  => array(
      'rule' => array('maxLength', 36),
      'required' => true
    ),
    'model_id' => array(
      'rule' => array('maxLength', 36),
      'required' => true
    ),
    'model'    => array(
      'rule' => 'alphaNumeric',
      'required' => true
    )
  );


  var $hasMany = array(
    'Rating' => array(
      'className'  => 'Rating',
      'foreignKey' => 'model_id',
      'conditions' => array('Rating.model' => 'rating'),
      'dependent'  => true,
      'exclusive'  => true
    )
  ); 
}

It has option to specify the model name and model id so I think my issue will be fixed if I will be able to specify the model name or any other parameter along with this Array. As I am newbie in CakePHP, someone please help me to find a solution.

Please check the rating plugin I am talking about here:

http://bakery.cakephp.org/articles/schneimi/2010/08/19/ajax-star-rating-plugin-1

  • 写回答

1条回答 默认 最新

  • dtdsbakn210537 2011-12-15 10:29
    关注

    The $hasMany attribute definition needs to go in the model you would like to rate. So for Album, it would look something like:

    /**
    * Album Model
    */
    class Album extends Model
    {
      var $name = 'Album';
    
      var $hasMany = array(
        'Rating' => array(
          'className'   => 'Rating',
          'foreignKey'  => 'model_id',
          'conditions' => array(
            'Rating.model' => 'Album'
          ),
          'dependent'   => true,
          'exclusive'   => true
        )
      ); 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP