cakePHP:如何在控制器中手动设置输入字段的错误验证 [英] cakePHP: how set error validation to input field manually in controller

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

问题描述

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

I want set error validation to input field manually in controller example:

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

其他问题:我想问:
bindModel(在这种情况下,我在行为中使用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 model but is bindModel cause loss of $var validate,too ?

推荐答案

在模型中定义,bindModel不会导致$ var validate的closs。

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

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

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:如何在控制器中手动设置输入字段的错误验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆