PHP development framework YiiFramework tutorial (16) UI component StarRating example
CStarRating is mainly used for scoring. a group of stars (five stars) are displayed for scoring.
The basic usage is as follows:
BeginWidget ('cactiveform');?>
Widget ('cstarrating', array (
'Model' => $ model,
'Attribute' => 'rating ',
'Name' => 'rating ',
'Value' => 3,
);?>
EndWidget ();?>
In the Controller, you can use $ _ POST ['rating'] to access the value of Star. for example:
Public function actionIndex ()
{
$ Model = new DataModel ();
$ Model-> rating = 3;
If (! Emptyempty ($ _ POST ['rating'])
{
$ Model-> rating =$ _ POST ['rating'];
If ($ model-> validate ()){
$ This-> render ('response', array (
'Model' => $ model,
));
Return;
}
}
$ This-> render ('index', array (
'Model' => $ model,
));
}
CStarRating can also be set to read-only. in this case, StarRating is used to display the score, and users cannot modify the score. This is achieved through 'readonly' => true.