[英]Lithium PHP framework - submitted model property disappears before save
I'm working on a project, built with Lithium PHP framework, and have a strange issue: 我正在开发一个使用Lithium PHP框架构建的项目,并且遇到一个奇怪的问题:
I have two controllers for users - one for the front-end of the site, and one for admin panel. 我有两个用于用户的控制器-一个用于网站的前端,一个用于管理面板。 Both of them have
edit()
method, which calls the save
method of the Users
model. 它们都具有
edit()
方法,该方法调用Users
模型的save
方法。
And the problem is this one: 问题是这个:
When I attempt to change the password in the admin panel - $request->data
contains the confirmPassword
POST field --- BUT --- validation rule for it never triggers. 当我尝试在管理面板中更改密码时-
$request->data
包含confirmPassword
POST字段---但---验证规则永远不会触发。 And when I attempt to register the user on the front-end - the validation for confirmPassword
triggers. 而且,当我尝试在前端注册用户时
confirmPassword
触发器的验证。
The methods have one and the same code: 这些方法具有相同的代码:
public function {add / edit} ($request, $user) {
if (!$request->data) {
return array(200, $user);
}
$success = $user->save();
return array($success, $user);
}
The validation rule is in the model, & it uses a custom validation, defined in config/bootstrap/validation.php
with this code: 验证规则在模型中,并且使用自定义验证,该验证在
config/bootstrap/validation.php
使用以下代码定义:
Validator::add('matchesPassword', function($value, $format, $options) { ...
And finally - the website is built with Lithium PHP framework (it's new for me) and uses li3_resources
, and all the controllers and models extend this Resource
class. 最后-该网站是使用Lithium PHP框架(对我来说是新的)
li3_resources
,并使用li3_resources
,所有控制器和模型都扩展了该Resource
类。
So ... where could this POST field disappears? 那么...此POST字段在哪里消失? ... Any clues?
...有什么线索吗? ...
...
Edit: when I wrote public function {add / edit} ($request, $user) {
I meant both methods: 编辑:当我编写
public function {add / edit} ($request, $user) {
我的意思是两种方法:
public function add($request, $user) { ...
public function edit($request, $user) { ...
Thanks. 谢谢。
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. 这导致验证规则在编辑时不会触发。
PS: I tried to dump the rules in the validation itself (in this class - https://github.com/UnionOfRAD/lithium/blob/master/util/Validator.php - in the annonimous function on line 469: PS:我想倾倒在确认自身的规则(在这个类- https://github.com/UnionOfRAD/lithium/blob/master/util/Validator.php -在上线469 annonimous功能:
return static::_filter(__FUNCTION__, $params, function($self, $params) {
but the dumping never happened ??? 但倾销从未发生??? ... probably if it worked there - this could save me some time ...
...可能在那里工作-这可以为我节省一些时间...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.