0
我有coba2的控制器。在功能actionAdmin我将搜索添加验证,因为当整数由非整数搜索它会给SQL错误yii在admim上添加验证页面
CDbCommand failed to execute the SQL statement: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "a" LINE 1: SELECT COUNT(*) FROM "yii_user" "t" WHERE id_user='a' ^. The SQL statement executed was: SELECT COUNT(*) FROM "yii_user" "t" WHERE id_user=:ycp0
这里是我的函数调用验证我的模型功能
public function actionAdmin()
{
$model=new coba2('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['coba2']))
$model->attributes=$_GET['coba2'];
if($model->validate()){
$this->render('admin',array(
'model'=>$model,
));
} else{
$model->unsetAttributes();
$this->render('admin',array(
'model'=>$model,
));
}
}
和这里是我的模型规则
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, salt, date_create, date_update, date_birth', 'required'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_user', 'numerical', 'integerOnly'=>true, 'on'=>'search'),
array('id_user, username, password, salt, date_create, date_update, date_birth', 'safe', 'on'=>'search'),
);
}
对不起,我的英语不好,但我需要帮助。 谢谢:)
什么是问题吗? – Pentium10 2012-08-05 14:41:35