I'm working on a project, built with Lithium PHP framework, and have a strange issue:
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.
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. And when I attempt to register the user on the front-end - the validation for confirmPassword
triggers.
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:
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.
So ... where could this POST field disappears? ... Any clues? ...
Edit: when I wrote public function {add / edit} ($request, $user) {
I meant both methods:
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:
return static::_filter(__FUNCTION__, $params, function($self, $params) {
but the dumping never happened ??? ... probably if it worked there - this could save me some time ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.