Home  >  Article  >  Backend Development  >  PHP development framework Yii Framework tutorial (16) UI component StarRating example

PHP development framework Yii Framework tutorial (16) UI component StarRating example

黄舟
黄舟Original
2017-01-21 10:23:021046browse

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,.

PHP development framework Yii Framework tutorial (16) UI component StarRating example

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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn