在重定向后保留验证数据

在重定向后保留验证数据

本文介绍了CakePHP:在重定向后保留验证数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已经看到这个问题在这里很多,但我找不到任何满意的答案,所以我会尝试把它有点不同:

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").

每种表单都会导致不同的控制器操作。验证后,cakephp试图显示用户/登录和用户/注册视图中的验证错误,但我没有,我不想那些视图,所以我被迫做一个重定向回到我的首页。但是,在重定向时,验证数据丢失。

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?

推荐答案

Cakephp在

$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.

更新:

如果您的重定向失去了属性值,请尝试将其保存在会话变量中。 invalidFields 会再次执行整个验证过程,而应改用 $ this-> ModelName-> validationErrors

invalidFields executes the whole validation process again and $this->ModelName->validationErrors should be used instead.

这篇关于CakePHP:在重定向后保留验证数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:31