Home > Article > Backend Development > PHP development framework Yii Framework tutorial (16) UI component StarRating example
CStarRating is mainly used for rating, showing a set of stars (5) for rating.
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 access the value of Star through $_POST['rating'], 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 , at this time StarRating is used to display the rating and the user cannot modify the rating. This is achieved through 'readOnly' => true,.
The above is the content of the PHP development framework Yii Framework tutorial (16) UI component StarRating example. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!