问题
I have seen this problem mentioned a lot here, but I couldn't find any satisfactory answer, so I'll try to formulate it a bit differently:
I have a login form and a registration form for users on the same page (let's call it the "frontpage").
Each form leads to a different controller action. Upon validation, cakephp is trying to display the validation errors in the users/login and users/register Views, but I don't have and I don't want those Views, so I'm forced to do a redirect back to my "frontpage". However, upon redirecting, the validation data is lost.
How do I go about keeping the validation data to be displayed on my frontpage, without having to add separate pages for the login and register functions?
回答1:
Cakephp keeps its validation errors in
$this->ModelName->invalidFields();
If you want it to behave persisten the i believe you will have to keep it in a session variable. i.e if your redirects are loosing the property value then try keeping it in a session variable.
Update:
invalidFields executes the whole validation process again and $this->ModelName->validationErrors should be used instead.
来源:https://stackoverflow.com/questions/12553192/cakephp-keep-validation-data-upon-redirect