Search with params

Hi to all. i have Cars table. One of fields is rating (from 1 to 5). I had created new actionSearch in CarsController and in new "search" view a form:

    <div class="row">

		<?php echo $form->labelEx($model,'rating',array('label'=>'Rating')); ?>

		<?php echo $form->checkBoxList(




                ); ?>

		<?php echo $form->error($model,'rating'); ?>


in Cars model:

	public function searchAdv()


		$criteria=new CDbCriteria;

                $stars = $this->rating; //it's wrong way


                $criteria->condition='stars IN ('.$stars.')';

		return new CActiveDataProvider(get_class($this), array(




in controller:

	public function actionSearch()


        $model=new Cars;

        $model->attributes=$_POST['Cars']; // here i put checked ratings





And the question is: How can i access $_POST[‘cars’] array from Cars model? Because $model->rating is empty.

$stars = $this->rating; //here must be checked array of rating, for ex: 1,5.

P.S.: sorry for amateurish question :)

You should check whether $_POST[‘Cars’] has value before you assign to attributes.

Ye, I know it. I dont check it because i know that POST is not empty.

I checked $model->attributes



And var_dump “says” that there is no ‘rating’ attribute. What Im doing wrong?

I announced rating variable in Cars model:

class Cars extends CActiveRecord



    public $rating;



I solved it. it was necessary to add rule for rating variable. ;D

	public function rules()