PHP development framework YiiFramework tutorial (16) UI component StarRating example

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.