a terrible bug about CGridView

I test to used CGridView。

But i meet some bugs. :unsure:

The First:




$criteria=new CDbCriteria;

$criteria->compare('Id',$this->Id);

$criteria->compare('UName',$this->UName,true);

$criteria->compare('Email',$this->Email,true);

$criteria->compare('Score',$this->Score,true);

$criteria->compare('Password',$this->Password,true);

$criteria->compare('UserType',$this->UserType,true);

$criteria->compare('UserGroup',$this->UserGroup);

$criteria->compare('State',$this->State,true);


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

'criteria'=>$criteria,

'pagination' => array( 'pageSize' => 30 ), 

));



THE $this->Score’s default value is 0.

I don’t set it at all~~~

please look at this photo:

1771

鏈懡~1.jpg

The default value is 0 .and it filter the data which score unequal to 0

If I delete it:




$criteria->compare('Score',$this->Score,true);



It were be okey~~~~

TKS~

If ‘0’ is showing up in the filter input for score, then it must be being set to the $model that you use as the basis for your search somehow, either as a GET parameter (in which case it is massively assigned to the model in the action, presuming you are using the default Gii-generated code), or by the model itself.

What kind of variable in your model is score? Does it directly correspond to a table column, or is it coded in the model?

You should include the url that generates this page (without making any ajax calls), the code in your action, the code in your view and your model code.

Could be that you have defined in the database a default value for that field… so when you create a model this field gets it’s default value…

to solve this… call unsetAttributes() - http://www.yiiframework.com/doc/api/1.1/CModel#unsetAttributes-detail




$model = new YourModel;

$model->unsetAttributes();



using something else like enum or a number larger than 0, the world will in peace. :slight_smile:

:lol:

THS for every one~~~

That’s kind of you ~~

I use




$model->unsetAttributes(); 



solved it!

Hope it can help another man who meet the same problem! ;D

Glad you got it working.

Can you confirm though that you had a default value in your database, just so that if other people come across this problem they know the reason?