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

问题描述 投票:0回答:1

代码在视图中

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

这里ProductGroupImage只是别名而不是实际模型。

在控制器中

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

上面的代码不会在视图中显示错误消息。

php cakephp-2.0
1个回答
-1
投票

我假设您正在触发模型验证,然后更新validationErrors数组。

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

然后,您可以更新errors变量并将其重新分配给validationErrors。

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

$this->Tardy->validationErrors = $errors;
© www.soinside.com 2019 - 2024. All rights reserved.