Nachdem ich cakePHP: how set error validation to input field manually in controller gelesen hatte, fragte ich mich, wie man einen validationError von einem Controller zeigt, wenn wir ein Formular ohne ein Modell verwenden?CakePHP 2.x: Wie setze ich validationErrors manuell ohne ein Modell?
So haben wir zum Beispiel eine Ansicht checkSomething.ctp
, mit einem Formular, das wir einreichen können.
echo $this->Form->create(false); // If we put "SomeModel" here, it would work.
echo $this->Form->input("myField");
Und sagen wir auf /Home/CheckSomething/
sind.
class HomeController extends AppController{
public function CheckSomething(){
// So manually validate a field
if(strlen($this->request->data["myField"]) < 5){
// myField is not valid, so we need to show an error near that field
$this->SomeModel->invalidateField("myField", "You must enter at least 5 characters");
// How to do this?
}
}
}
Wir können hier kein Modell verwenden ... Wie setzt man einen validationError für ein Feld ohne Modell? Wie man ein Feld manuell ungültig macht, das von solch einem Formular kommt?
Das ist genau die Art und Weise, dieses Problem zu lösen. Vielen Dank! – Koen