简体   繁体   English

在模型验证规则失败后,在cakephp 2.0中保留某些变量

[英]Keeping certain variables after model validation rules fail in cakephp 2.0

So I'm using jquery tabs for a page with a form, and we're using certain php variables like $image (with data such as dimensions and path) in if isset conditions inside the view to "unlock" further tabs as the user completes actions (such as uploading an image at this example). 因此,我正在使用带有表单的页面的jquery选项卡,并且我们在视图中的if isset条件下使用某些php变量(例如$image (带有尺寸和路径等数据))以“解锁”用户的其他选项卡完成操作(例如,在此示例中上载图像)。 At some point I have to use some validation rules, and the problem is if the user makes an error and validation rules fail, the page is reloaded with the variables $image etc gone, so the user basically has to start the form from the beginning (locked tabs and all). 在某些时候,我必须使用一些验证规则,问题是如果用户出错并且验证规则失败,页面将重新加载变量$image等,因此用户基本上必须从头开始创建表单。 (锁定的标签和所有标签)。

At the moment I'm using something like this: 此刻我正在使用这样的东西:

if ($this->Report->save($this->data)) { //validation rules run here
    //do stuff
else{
    $this->set("err", 1);

so I can at least have some of the tabs unlocked on page reload using the $err variable, but I also need to maintain specific variables with actual data like $image that I mentioned before (to show a preview), which I cannot figure out a way to do. 因此,至少可以使用$err变量在页面重新加载时解锁某些选项卡,但是我还需要使用我之前提到的实际数据(例如$image维护特定变量(以显示预览),但我无法弄清楚一种方法。

Any thoughts? 有什么想法吗?

您可以将数据存储在会话中,并在适当时将其删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM