如何在CgridView中获得CStarRating - Yii

时间:2014-04-13 22:28:11

标签: yii

如何让每一行成为starRating。我想展示当前的明星,如果用户想要更新星星,他可以点击更新它。

我的错误是未定义的$ data。

gridview的:

...
'columns'=>
...
array (
    'name' => 'star',
    'type' => 'raw',
    'value'=>'$this->grid->controller->widget("CStarRating",
                array("starCount"=>"5",
                "minRating"=>"1",
                "maxRating"=>"5",
                "ratingStepSize"=>"1",
                "allowEmpty"=>false,
                "name"=>"rating".$data->id,
                "callback"=>"function(){
                url = "controller/action";
            jQuery.getJSON(url, {id: "$data->id", val: $(this).val()},
                        function() {
                           if (data.status !== "success"){
                                    alert("error");
                 }});}",),true)',                           
),

3 个答案:

答案 0 :(得分:2)

'value'=> function($data){
         $controller = Yii::app()->getController();
         return $controller->widget("CStarRating",
            array("starCount"=>"5",
            "minRating"=>"1",
            "maxRating"=>"5",
            "ratingStepSize"=>"1",
            "allowEmpty"=>false,
            "name"=>"rating".$data->id,
            "callback"=>'function(){
            url = "controller/action";
        jQuery.getJSON(url, {id: "'.$data->id.'", val: $(this).val()},
                    function() {
                       if (data.status !== "success"){
                                alert("error");
             }});}',),true);
         }, 

答案 1 :(得分:1)

试试这个:

array (
'name' => 'star',
'type' => 'raw',
'value'=>'$this->grid->controller->widget("CStarRating",
            array("starCount"=>"5",
            "minRating"=>"1",
            "maxRating"=>"5",
            "ratingStepSize"=>"1",
            "allowEmpty"=>false,
            "name"=>"rating".$data->id,
            "callback"=>"function(){
            url = "controller/action";
        jQuery.getJSON(url, {id: \'.$data->id.\', val: $(this).val()},
                    function() {
                       if (data.status !== "success"){
                                alert("error");
             }});}",),true)',                           
),

答案 2 :(得分:-1)

在我看来你的报价太多了。改变;

'value'=>'$this->grid->controller->widget("CStarRating",

'value'=>$this->grid->controller->widget("CStarRating",