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