简体   繁体   English

锂PHP框架-验证规则不会在现有字段上触发…

[英]Lithium PHP framework - validation rule doesn't trigger on existing field …

I have a form for changing password. 我有一个更改密码的表格。 So the POST data include the fields password and passwordConfirm . 因此,POST数据包括字段passwordpasswordConfirm

Also I have validation rules for these 2 properties in the Users model, and they work fine on registration - ie creating new user. 我在Users模型中也有针对这2个属性的验证规则,它们在注册时可以正常工作-即创建新用户。 But when updating existing user - they don't trigger. 但是在更新现有用户时-他们不会触发。

In that case - I dumped the data of the entity inside the save() method of the basic model class: 在这种情况下,我将实体的数据转储到基本模型类的save()方法内:

$entity->data()

I see that both submitted fields/properties are already there ... and they are different. 我看到两个提交的字段/属性都已经存在了……而且它们是不同的。 Immediately after that I dumped 在那之后,我立即放弃了

$entity->validates()

and this gives me true ?!?! 这给了我true ?!?! ... ...

How is that even possible ??? 这怎么可能呢 ??? ... ...

PS: I'm dumping inside a core class of the framework ... and not some 3rd party library ... PS:我要转储到框架的核心类中……而不是某些第三方库中……

I found the reason for the problem :) ... 我找到了问题的原因:) ...

On the validation rules, defined in the model by the previous developers, there was this clause: 在以前的开发人员在模型中定义的验证规则上,有以下子句:

'on' => 'create'

which was causing the validation rule not to trigger when editing. 这导致验证规则在编辑时不会触发。

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

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