Ich sehe einige Links sagen, dass Yi2 eindeutige Validierung nur für Ajax-Validierung ist (Aber ich finde keine Best Practice zu folgen.). Also ich frage dies für die Nicht-Ajax-Validierung in Yii2yii2 Unique Validation (non-ajax) funktioniert nicht
mein Modell Regeln sind
['name', 'unique', 'targetAttribute' => 'function_id','message' => 'name must be unique.'],
Meine Controller-Funktionen normale actionCreate sind()
Anybody Lösung dafür? Vielen Dank im Voraus
Edit: Für Ajax ok.I Hat, Mein Controller-Code jetzt
$model = new JobFunctionRole();
$model->scenario = 'insert';
$jobFunction=JobFunction::find()->all();
if(Yii::$app->request->post()){
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->job_function_role_id]);
}
} else {
return $this->render('create', [
'model' => $model,'jobFunction'=>$jobFunction
]);
}`
Aber Seite umleitet und zeigt leere Seite.
Tun Sie es in Ajax Validierung überprüfen müssen. Ich werde dich führen. –
ok.Ich habe, Mein Controller Code ist jetzt: Siehe Edits in meiner Frage. Danke! :) – Jackhad
Conceptually, auf welche Weise Sie function_id für Scheckeindeutigkeit verwenden? – scaisEdge