简体   繁体   English

Cakephp 2.x在没有模型的控制器中设置自定义验证消息

[英]Cakephp 2.x set custom validation message in Controller without Model

Code in View 查看代码

<?= $this->Form->input('ProductGroupImage.image', array("class" => "", "type" => "file")); ?>

Here ProductGroupImage is just alias not a actual model. 在这里, ProductGroupImage只是别名而不是实际模型。

In Controller 在控制器中

$this->validationErrors['ProductGroupImage']['image'] = "File not Valid"

Above Code does not show Error message in view. 上面的代码在视图中不显示错误消息。

i assume that you are triggering the validation on model and then you updating your validationErrors array. 我假设您正在触发模型验证,然后更新了validationErrors数组。

if (!$this->ProductGroupImage->validates()) {
    $errors = $this->ProductGroupImage->validationErrors;
}

You can then update the errors variable and the reassign it to the validationErrors. 然后,您可以更新错误变量,并将其重新分配给validationErrors。

if (isset($this->ProductGroupImage->validationErrors['execused_referral_by'])) {
$errors['execused_referral_by'] = "Please Select Excused By";
}

$this->Tardy->validationErrors = $errors;

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

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