本文介绍了cakePHP:如何在控制器中手动将错误验证设置为输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制器中手动将错误验证设置为输入字段例子:

I want set error validation to input field manually in controllerexample:

  if ($remainTime < 30) {
      ..... set error validation in here (error: limitTime ), ( error is not in model )
  }

其他问题:我想问:bindModel(在这种情况下,我在 Behaviors 中使用 bindModel)会导致与其他模型的关系丢失但是 bindModel 也会导致 $var validate 丢失吗?

other question: i want to ask :bindModel ( in this case , I use bindModel in Behaviors ) 'll cause loss of relationship with other modelbut is bindModel cause loss of $var validate,too ?

推荐答案

如果模型中定义了 $validate,bindModel 不会导致 $var validate 的关闭.

if the $validate is defined in the model, bindModel wont cause closs of $var validate.

至于你的首要问题;您可以设置/取消设置/更新模型的 $validationErrors..eg

As for you primary question; you can set/unset/update $validationErrors of the models..eg

($remainTime < 30) {
   $this->Model->validationErrors['limitTime'] = "time is less than 30";
}

这篇关于cakePHP:如何在控制器中手动将错误验证设置为输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 16:08